Chrome Extension

Array.forEach() in javascript

var myarray = ['1', '2', '3'];

myarray.forEach(function(item, index) {
    console.log("item is : ", item, ", index is : ", index)
});
Output
item is : 1 , index is : 0
item is : 2 , index is : 1
item is : 3 , index is : 2

Array.forEach() function in javascript is used to loop through the elements of an array. You can find item and index in its callback function as parameters. 

Search history ×