9951 explained code solutions for 126 technologies


javascript-lodashHow do I use the Lodash range function in JavaScript?


The _.range() function in Lodash is used to create an array of numbers from a given start and end point. It is a convenient alternative to using a for loop to create an array of numbers.

Example

let numbers = _.range(1, 10);
console.log(numbers);

Output example

[1, 2, 3, 4, 5, 6, 7, 8, 9]

Code explanation

  • let numbers: Creates a variable called numbers to store the array of numbers.
  • _.range(): Calls the Lodash range function, which will create an array of numbers.
  • 1, 10: The first argument is the start number, in this case 1. The second argument is the end number, in this case 10.
  • console.log(numbers): Logs the array of numbers to the console.

Helpful links

Edit this code on GitHub