forEach() method calls a function for each element in the array.
Syntax
array.forEach(callback[, thisObject]);
Parameter Details
- callback โ Function to test for each element.
- thisObject โ Object to use as this when executing callback.
Return Value
Returns created array.
Example
let num = [7, 8, 9]; num.forEach(function (value) { console.log(value); });
On compiling, it will generate the following JavaScript code โ
var num = [7, 8, 9]; num.forEach(function (value) { console.log(value); });
Its output is as follows โ
7 8 9
Previous page:-Click Here