Basic JavaScript Question:

Download Job Interview Questions and Answers PDF

How to loop through array in JavaScript?

JavaScript Interview Question
JavaScript Interview Question

Answer:

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>

Download JavaScript Interview Questions And Answers PDF

Previous QuestionNext Question
How do use javascript to open a chatque on a webpage i have only when someone clicks from a specific link. i.e. when anybody click a specific link to go to said webpage. the javascript will see that it came from the specific link and run its function?How to write Hello World on the web page?