1const avengers = ['thor', 'captain america', 'hulk'];
2avengers.forEach((item, index)=>{
3 console.log(index, item)
4})
1const array1 = ['a', 'b', 'c'];
2
3array1.forEach((element) => {
4 console.log(element)
5});
6
7// expected output: "a"
8// expected output: "b"
9// expected output: "c"
1// Arrow function
2forEach((element) => { ... } )
3forEach((element, index) => { ... } )
4forEach((element, index, array) => { ... } )
5
6// Callback function
7forEach(callbackFn)
8forEach(callbackFn, thisArg)
9
10// Inline callback function
11forEach(function callbackFn(element) { ... })
12forEach(function callbackFn(element, index) { ... })
13forEach(function callbackFn(element, index, array){ ... })
14forEach(function callbackFn(element, index, array) { ... }, thisArg)
15