Here's an example of how to loop through an array with an index using a for...of loop in TypeScript:
index.ts123 chars6 lines
Output:
index.ts32 chars4 lines
Alternatively, you could use a for...of loop to achieve the same result:
index.ts129 chars6 lines
Output:
index.ts32 chars4 lines
The entries()
method returns an iterator that produces an array of [index, value] pairs for each element in the array. Using destructuring, we can assign each pair to variables inside the loop.
gistlibby LogSnag