![]() |
In TypeScript the Symbol.iterator function plays a role, in allowing iteration over arrays using for…of loops and other iterator-based mechanisms. This built-in function eliminates the need, for definition when working with arrays simplifying the process of accessing elements in a manner. Syntax:const iterator: Iterator<T> = array[Symbol.iterator]();
Parameter:
Return Value:
Example 1: We will iterate each element of an array by using a, for…of loop and see the working of Symbol.iterator Method. Javascript
Output: 1 Example 2: We are going to manually iterate using the next method and see the working of Symbol.iterator Method. Javascript
Output: Pankaj |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |