[javascript] Access to ES6 array element index inside for-of loop

Use Array.prototype.keys:

_x000D_
_x000D_
for (const index of [1, 2, 3, 4, 5].keys()) {_x000D_
  console.log(index);_x000D_
}
_x000D_
_x000D_
_x000D_

If you want to access both the key and the value, you can use Array.prototype.entries() with destructuring:

_x000D_
_x000D_
for (const [index, value] of [1, 2, 3, 4, 5].entries()) {_x000D_
  console.log(index, value);_x000D_
}
_x000D_
_x000D_
_x000D_