How can the current number of i be accessed in a for of loop?

You mean this?

array = ["one", "two", "three"];

for (i = 0; i < array.length; i++) {
  console.log(i); // Logs the current index number;
  console.log(array[i]); // Logs the index matching in the array;
}

Also a good comment from Kaiido was that you can use this to get the value from the array directly as a variable.

for (var ind = 0, i=array[ind]; ind < array.length; i=array[++ind]) {
    console.log(i);
    console.log(ind);
}

nothing simple ... if you want "simple access" to both the item and the index in a loop over an array, use forEach e.g.

array.forEach(function(item, index) { 
... 
});

or as T.J. Crowder pointer out (and I missed the ES6 tag)

array.forEach((item, index) => { 
    ... 
});

like many programming languages, javascript has multiple ways to do similar things, the skill is in choosing the right tool for the job


You can use the entries function. It will return a index/value pair for each entry in the array like:

[0, "one"]
[1, "two"]
[2, "three"]

Use this in tandem with array destructuring to resolve each entry to the appropriate variable name:

const arr = ["one", "two", "three"]
for(const [index, value] of arr.entries()) {
  console.log(index, value);
}

Babel REPL Example