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

// Defining underscore contrib variable
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

// Defining underscore contrib variable
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



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
Underscore.js _.iterators.select() Method Underscore.js _.iterators.select() Method
D3.js schemePiYG[] Function D3.js schemePiYG[] Function
Reference and Copy Variables in JavaScript Reference and Copy Variables in JavaScript
How to get the height of scroll bar using JavaScript ? How to get the height of scroll bar using JavaScript ?
How to Detect Keypress using JavaScript ? How to Detect Keypress using JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
10