Underscore.js _.iterators.numbers() Method
Last Updated :
07 Nov, 2022
With the help of _.iterators.numbers() method, we can get the integer value from the iterator function which will begin with the argument given in this method and increment one by one when invoked by using this method.
Syntax:
_.iterators.numbers(start)
Parameter: This method accepts a single parameter as mentioned above and described below:
- start: This parameter holds the starting value.
Return value: Return the value starts from given argument.
Note: To execute the below examples you have to install the underscore-contrib library by using this command prompt we have to execute the following command.
npm install underscore-contrib
Below examples illustrate the Underscore.js _.iterators.numbers() method in JavaScript:
Example 1: In this method, we can see that by using _.iterators.numbers() method, we are able to get the integer value from the iterator function and increment the value by one when invoked every time by using this method.
Javascript
var _ = require( 'underscore-contrib' );
var geek = _.iterators.numbers(20);
for ( var i = 0; i < 5; i++) {
console.log(geek());
}
|
Output:
20
21
22
23
24
Example 2:
Javascript
var _ = require( 'underscore-contrib' );
var geek = _.iterators.numbers(8);
for ( var i = 0; i < 10; i++) {
console.log(geek());
}
|
Output:
8
9
10
11
12
13
14
15
16
17
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...