JavaScript: foreach loop

foreach loop The foreach loop is one of the JavaScript statements that allows you to iterate over a set of values in a array. The syntax of the foreach loop is as follows:

The syntax for the for each loop is as follows:

var arr = [1,2,3,4,5,6,7,8,9,10];

arr.forEach(function(item, index, array) {
  console.log(item, index);
});

You can compare all the options of array iteration

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: