.forEach .map() loop JavaScript
For Each .forEach iterates the elements of an array but does not return a value.
const a = [1, 2, 3];
const newArray = a.forEach((num, index) => {
//do something
});
// newArray = undefined
Map .map iterates the elements of an array but return a new array.
const a = [1, 2, 3];
const newArray = a.map(num => {
return num * 2;
});
// newArray = [2, 4, 6]