In the above program, the forEach() method takes myFunction() function that displays each element of a students array.Īs we have seen in the above example, the forEach() method is used to iterate over an array, it is quite simple to update the array elements. The forEach() method is used to iterate over an array. index (optional) - the index of the current elementĪrr (optional) - the array of the current elements.function(currentValue, index, arr) - a function to be run for each element of an array.The syntax of the forEach() method is: array.forEach(function(currentValue, index, arr)) The forEach() method can also be used on Maps and Sets. The forEach() method calls a function and iterates over the elements of an array.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |