how to get a range of numbers in javascript code example

Example 1: range javascript

[...Array(5).keys()];
 => [0, 1, 2, 3, 4]

Example 2: javascript range of integers

// n is your max range
[...Array(n).keys()]

let n = 10
[...Array(n).keys()] // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Example 3: javascript range of integers

var list = [];
for (var i = lowEnd; i <= highEnd; i++) {
    list.push(i);
}

Example 4: sum all numbers in a range javascript

ar sum = 0;
  for (var i = Math.min(...arr); i <= Math.max(...arr); i++) {
    sum += i;
  }

Example 5: for in range javascript

function* range(start=0, end=null, step=1) {
  if (end == null) {
    end = start;
    start = 0;
  }

  for (let i=start; i < end; i+=step) {
    yield i;
  }
}