A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-range-method/ below:

Lodash _.range() Method - GeeksforGeeks

Lodash _.range() Method

Last Updated : 20 Oct, 2023

Lodash _.range() method is used to create an array of numbers progressing from the given start value up to, but not including the end value. A step of -1 is used if a negative value of start is specified without an end or step. If the end is not specified, it's set to start with the start and then set to 0.

Syntax:
_.range([start=0], end, [step=1]);
Parameters: Return Value:

It returns an array with the given range of numbers.

Example 1: In this example, we are printing 5 values in the console as we are passing 5 as an end parameter to the _.range() method.

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

Output:

[0, 1, 2, 3, 4]

Example 2: In this example, we are passing 0 as a start, 10 as an end and 2 as step and passing these parameter to the _.range() method.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

// Using the _.range() method
// with the step taken as 2
let range_arr = _.range(0, 10, 2);

// Printing the output  
console.log(range_arr); 

Output:

[0, 2, 4, 6, 8]

Example 3: In this example, we are passing -1 as a start, -11 as an end and -2 as step and passing these parameter to the _.range() method.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

// Using the _.range() method
// with the step taken as -2
let range_arr = _.range(-1, -11, -2);

// Printing the output  
console.log(range_arr); 

Output:

[-1, -3, -5, -7, -9]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4