Underscore.js _.iterators.numbers() Method

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 illutarte 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

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable 
var _ = require('underscore-contrib');
  
var geek = _.iterators.numbers(20);
  
for(var i = 0; i < 5; i++) {
    console.log(geek());
}

chevron_right


Output:

20
21
22
23
24

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable 
var _ = require('underscore-contrib');
  
var geek = _.iterators.numbers(8);
  
for(var i = 0; i < 10; i++) {
    console.log(geek());
}

chevron_right


Output:

8
9
10
11
12
13
14
15
16
17

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.