Skip to content
Related Articles

Related Articles

Lodash _.rangeRight() Method
  • Last Updated : 09 Sep, 2020

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);

chevron_right


Output:

[12, 9, 6, 3, 0]

Example 3:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);

chevron_right


Output:

[-8, -6, -4, -2, 0]

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :