In tis typescript blog we ar3e going to see using of for each statement in typescript.
foreach in TypeScript :
The forEach() method is an array method which is used to execute a function on each item in an array. We can use it with the JavaScript data types like Arrays, Maps, Sets, etc. It is a useful method for displaying elements in an array.
Loop initialization :
The variables involved in the loop condition are given initial, acceptable values during the loop initialization. The action only takes place once before the loop starts
Declare foreach In TypeScript :
Syntax :
array.forEach(callback[, thisObject]);
Example :
var num = [5, 15, 20];
num.forEach(function (value) {
console.log(value);
});
Disadvantage of forEach() :
The following are the disadvantages of the use of the forEach() method
- It does not provide a way to stop or break the forEach() loop.
- It only works with arrays.
For any Help or Queries Contact us on info@crmonce.com or +918096556344