Array Higher Order Functions
- .forEach()
- .map()
- .reduce()
- .filter()
.forEach()
.forEach() iterates through each element executing a provided function for each element.
const array = ["jack", "and", "jill", "went", "up", "the", "hill"];
function displayString(str){
console.log(str);
}
array.forEach(displayString);
Output:
jack
and
jill
went
up
the
hill
You can use an anonymous function (most common) as well
const array = ["jack", "and", "jill", "went", "up", "the", "hill"];
array.forEach((element) => { console.log(element); });