This post shows how to use forEach in TypeScript with an example.
TypeScript forEach Example
The forEach() method is an array method that is used to execute a function on each item in an array.
// Iterate Through Array
let programmingLangs : string[] = ['C', 'C++', 'Java', 'JavaScript'];
// using forEach() method
programmingLangs.forEach(element => {
console.log(element);
});
Output:
C:\typescript-tutorial> tsc for-loops.ts
C:\typescript-tutorial> node for-loops.js
C
C++
Java
JavaScript
Comments
Post a Comment