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