How to Use For Each loop in JavaScript
For Each Loop In JavaScript Hello Guys, Having trouble in understanding the concept of the for each loop in javascript. or having trouble finding the correct source code. Then don't worry this post is for you. What is For Each Loop: this is the loop which automatically iterates through all the elements of an array, it helps in the working with the dynamic array. Let's start working. In javascript for-each loop works in a different way. Here we have to create a function which will be passed to the foreach function of the array. Enough discussion. Start working. First, create an array of names of the actor. var heros = ["Tony","Captain","Batman","SuperMan"] Now create the function with the logic that has to be passed in the for each loop. function myfunc(item){ console.log(item + " is a very good superhero"); } Now call the function in the foreach function of array // running the foreach loop 4 times heros.forEach(myfunc); You c