create array of n elements javascript code example
Example 1: create an array from 1 to n javascript
Array.from(Array(10).keys())
[...Array(10).keys()]
Array.from({length: 10}, (_, i) => i + 1)
Example 2: es6 create array with increasing number
Array.from(Array(10).keys())
Example 3: javascript fill array with range
function range(start, end) {
return Array(end - start + 1).fill().map((_, idx) => start + idx)
}
var result = range(9, 18);
console.log(result);
Example 4: javascript create array from 1 to n
[...Array(n+1).keys()].slice(1)