Files
30-seconds-of-code/snippets/initialize-array-with-range.md
2017-12-07 12:55:56 +02:00

325 B

Initialize array with range

Use Array(end-start) to create an array of the desired length, map() to fill with the desired values in a range. You can omit start to use a default value of 0.

var initializeArrayRange = (end, start = 0) =>
  Array.apply(null, Array(end-start)).map( (v,i) => i + start );