TypeScript – Array forEach()

forEach() method

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

Leave a Reply