Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

For-in loop on array

  • for
  • in

We don't have to use the C-style for-loop on arrays. We can use the simpler, for-in construct. It will iterate over the index of the array.

"use strict";

var names = ["Foo", "Bar", "Qux"];
var v;
for (v in names) {
    console.log(v);
}
// 0
// 1
// 2