loading
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const fruits = [ 'pineapple', 'apple', 'banana', 'pear' ];

console.log('filter() example');
const matchedFruits = fruits.filter((element) => {
    return element.includes('apple');
});

console.log('matchedFruits =', matchedFruits, '\n');


console.log('for loop example');
let matchedFruitsAgain = [];
for (let i = 0; i < fruits.length; i++) {
    if (fruits[i].includes('apple')) {
        matchedFruitsAgain.push(fruits[i]);
    }
}

console.log('matchedFruitsAgain =', matchedFruitsAgain);