JavaScript wylicz za pomocą indeksu

const iterable = [...];
for (const [index, elem] in iterable.entries()) {
  f(index, elem);
}

// or
iterable.forEach((elem, index) => {
  f(index, elem);
});
Angry Alpaca