Languages
[Edit]
EN

TypeScript - foreach with index

8 points
Created by:
Paluskitten
356

In TypeScript it is possible to create foreach with index in following ways.

1. Array.forEach method example

Edit

Output:

0 : a
1 : b
2 : c

Run it online here.

2. Index variable with foreach example

Edit

Output:

0 : a
1 : b
2 : c

Run it online here.

3. Array.map method example 

Edit

Example:

Output:

0 : a
1 : b
2 : c

Run it online here.

4. yield based conversion example

Edit

Example:

Compiling and running:

Output:

0 : a
1 : b
2 : c

Run it online here

Note: for yield keyword support --downlevelIteration parameter during compilation is necessary.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

TypeScript

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join