Friday, September 19, 2025
HomeLanguagesJavascriptLodash _.rangeRight() Method

Lodash _.rangeRight() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.rangeRight() method is used to create an array of numbers progressing from the given start value to the given, but not including, the given end value. It populates the values in descending order. A step value of -1 is used if a negative start is specified without an end or step. If the end is not specified, it’s set to start with the start then set to 0.

Syntax:

_.rangeRight( start, end, step )

Parameters: This method accepts three parameters as mentioned above and described below:

  • start: It is a number that specifies the start of the range. It is an optional value. The default value is 0.
  • end: It is a number that specifies the end of the range.
  • step: It is a number that specifies the amount that the value in the range is incremented or decremented. The default value is 1.

Return Value: It returns an array with the range of numbers in descending order.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");            
    
// Using the _.rangeRight() method 
let range_arr = _.rangeRight(6); 
        
// Printing the output  
console.log(range_arr);


Output:

[5, 4, 3, 2, 1, 0]

Example 2:

Javascript




// Requiring the lodash library  
const _ = require("lodash");            
    
// Using the _.rangeRight() method
// with the step taken as 3
let range_arr = _.rangeRight(0,15,3); 
        
// Printing the output  
console.log(range_arr);


Output:

[12, 9, 6, 3, 0]

Example 3:

Javascript




// Requiring the lodash library  
const _ = require("lodash");            
    
// Using the _.rangeRight() method
// with the step taken as -2
let range_arr = _.rangeRight(0,-10,-2); 
        
// Printing the output  
console.log(range_arr);


Output:

[-8, -6, -4, -2, 0]
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

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6666 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS