Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptUnderscore.js _.iterators.range() Method

Underscore.js _.iterators.range() Method

With the help of _.iterators.range() method, we can get the iterator function that gives the value within a given range which is specified into arguments and got incremented whenever invoked by using this method.

Syntax:

_.iterators.range(from, to, by)

Parameter: This method accepts three parameter as mentioned above and described below: 

  • from: This parameter holds the starting value of the range.
  • to: This parameter holds the ending value of the range.
  • by: This parameter holds the gap between to continues value in the range.

Return: Return the value within a given range.

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 example illustrate the Underscore.js _.iterators.range() method in JavaScript: 

Example 1: In this example, we can see that by using _.iterators.range() method, we are able to get the values from iterator function who given the incremented value every time whenever invoked.

Javascript




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


Output:

15
20
25
30
35...

Example 2:

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib');
 
var geek = _.iterators.range(5, Infinity, 2);
 
for(var i = 0; i < 3; i++) {
    console.log(geek());
}


Output:

5
7
9...
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments