var i; for (i = 0; i < substr.length; ++i) { ..." /> How To Loop Through Array In JavaScript? var i; for (i = 0; i < substr.length; ++i) { ..." /> var i; for (i = 0; i < substr.length; ++i) { ..." />
Answers

Question and Answer:

  Home  JavaScript

⟩ How to loop through array in JavaScript?

There are various way to loop through array in JavaScript.

Generic loop:

<script langugage="javascript">

var i;

for (i = 0; i < substr.length; ++i) {

// do something with `substr[i]`

}

</script>

ES5's forEach:

<script langugage="javascript">

substr.forEach(function(item) {

// do something with `item`

});

</script>

jQuery.each:

<script langugage="javascript">

jQuery.each(substr, function(index, item) {

// do something with `item` (or `this` is also `item` if you like)

});

</script>

 162 views

More Questions for you: