foreach method of array in javascript 1

foreach method of array in javascript

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})

Here is what the above code is Doing:
1. We’re creating an array called avengers.
2. We’re using the forEach method to loop through the array.
3. We’re passing in a callback function to the forEach method.
4. The callback function takes in two parameters: item and index.
5. The callback function is going to log the index and item to the console.

Similar Posts