Underscore.js _.iterators.List() Method

With the help of _.iterators.List() method, we can get the iterator which when called up gives the next value of the List by using this method.
Syntax :
_.iterators.List(array:Array)
Parameters value: This method accepts a single parameter as mentioned above and described below:
- array: It holds the array where the method will be applied.
Return: Return the iterator for a List.
Example 1: In this example, we can see that by using _.iterators.List(array:Array) method, we are able to get the iterator which is invoked every time we call the iterator and return values of the List when called.
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); var gfg = _.iterators.List(["Geeks", "for", "Geeks"]); for(var i = 0; i < 3; i++) { console.log(gfg()); } |
Output :
Geeks for Geeks
Example 2 :
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); var gfg = _.iterators.List(["A", "B", "C", "D", "E"]); for(var i = 0; i < 3; i++) { console.log(gfg()); } |
Output :
A B C D E
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



