forEach()
ES5+Executes a provided function once for each array element.
Syntax
array.forEach(callback(element, index, array), thisArg)Parameters
callback Function Function to execute on each element
Return Value
undefined
undefined - forEach does not return a value
Examples
JavaScript
const fruits = ['apple', 'banana', 'cherry'];
fruits.forEach((fruit, index) => {
console.log(index + ': ' + fruit);
}); Output:
// 0: apple
1: banana
2: cherry