Home » JavaScript » JavaScript For Loop » Question
  1. Consider the following code snippet.
    for(var n in m)
    console.log(m[n]);

    The above code is equivalent to which code?
    1. for (var i = 1;i < a.length;i++)
      console.log(a[i]);

    2. for (var i = 0;i < a.length;i++)
      console.log(a[i]);

    3. for (int i = 0;i < a.length;i++)
      console.log(a[i]);

    4. for (var i = 0;i <= a.length;i++)
      console.log(a[i]);

    5. None of these
Correct Option: B

The in variable does the same task of traversing the array starting from the 0 index. The for/in loop makes it easy to do the same that we do using a for.



Your comments will be displayed only after manual approval.