How to Use For Each loop in JavaScript
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMdsTYKiG9_AGyzSTX9AtVPMDKgwB4SUu4qBnc6osTUkLqy9L_k71Nq3he9kz8EoKHPDWp6rZ2n2Dso_U1Cs00nxkZvRgxsHZonwAUS_x1UTDTLH90V4e-qBdAtsmh4_IDOtTQ27I9VcUw/s640/jslogo.png)
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