DEV Community

Discussion on: JavaScript/Typescript Tips compilation 2021🚀

Collapse
 
jamesthomson profile image
James Thomson

If you wanted an index to reference, but want to use for...of you'd be better off (performance wise) using a variable to track it.

const array1 = ['a', 'b', 'c'];
let i = 0;
for (const element of array1) {
  console.log(element,i);
  i++;
}
Enter fullscreen mode Exit fullscreen mode