Advertisement
Virajsinh

Range in JavaScript

Mar 9th, 2024 (edited)
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.30 KB | Source Code | 0 0
  1. // https://www.freecodecamp.org/news/javascript-range-create-an-array-of-numbers-with-the-from-method/
  2.  
  3. const arrayRange = (start, stop, step) =>
  4. Array.from(
  5.     { length: (stop - start) / step + 1 },
  6.     (value, index) => start + index * step
  7. );
  8.  
  9. console.log(arrayRange(1, 5, 1)); // [1,2,3,4,5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement