Languages
[Edit]
EN

TypeScript - foreach loop

7 points
Created by:
Marcin
2444

In TypeScript it is possible to use foreach in following ways.

1. foreach syntax example

let array = [ 1, 2, 3, 'text' ];

for(let entry of array)
    console.log(entry);

Output:

1
2
3
text

2. forEach method example

let array = [ 1, 2, 3, 'text' ];

array.forEach((entry : any, index : number) : void => {
    console.log(entry);
});

Output:

1
2
3
text

 

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍