forEach()
→ Executes a function on each item, but returns undefined.map()
→ Transforms elements and returns a new array.
Example:
let arr = [1, 2, 3];
arr.forEach(x => console.log(x * 2)); // prints 2, 4, 6
console.log(arr.map(x => x * 2)); // [2, 4, 6]
Leave a Reply