Array.map()
Array.filter()
Array.forEach()
Array.includes()
Array.push()
both execute function once for each array element. but map creates a NEW ARRAY and forEach only EXECUTES.
const array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.map(x => x * 2);
console.log(map1);
// expected output: Array [2, 8, 18, 32]
const array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.forEach(x => console.log(x * 2));
// expected output
// 2
// 8
// 18
// 32
const pets = ['cat', 'dog', 'bat'];
if(pets.includes('cat')){
pets.push('cat tower')
console.log(pets);
};
// output
// Array ["cat", "dog", "bat", "cat tower"]