JavascriptJavaScript — Loop Over an Array with forEach() Method

JavaScript — Loop Over an Array with forEach() Method

You can use the forEach() method to loop over an array and execute a function on each element of the array.

Example

var pets = ['dog', 'cat', 'monkey'];

pets.forEach(function(element) {
  console.log(element);
});

// expected output: "dog"
// expected output: "cat"
// expected output: "monkey"

 

For more information:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

Categories: Javascript Tags: , ,

Comments

No Comments Yet. Be the first?

Post a comment

Your email address will not be published. Required fields are marked *