Interviewer And Interviewee Guide

JavaScript Interview Question:

How to loop through array in JavaScript?

Submitted by: Muhammad
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>
Submitted by: Muhammad

Read Online JavaScript Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.