TypeScript forEachThe 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. SyntaxWe can declare the forEach() method as below. The forEach() method executes the provided callback once for each element present in the array in ascending order. Parameter Details1. callback: It is a function used to test for each element. The callback function accepts three arguments, which are given below.
Note: These three arguments are optional.2. thisObject: It is an object to use as this when executing the callback. Return ValueIt will return the created array. Example with stringThe corresponding JavaScript code is: Output: Example with numberOutput: Disadvantage of forEach()The following are the disadvantages of the use of the forEach() method:
Next TopicTypeScript Map |