how to create an array of length n in javascript code example
Example 1: es6 create array with increasing number
Array.from(Array(10).keys())
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Example 2: array length javascript
var numbers = [1, 2, 3, 4, 5];
var length = numbers.length;
for (var i = 0; i < length; i++) {
numbers[i] *= 2;
}
// numbers is now [2, 4, 6, 8, 10]
Example 3: how to fill array with consecutive numbers javascript
Array.from({length: n}, (_, i) => i + 1)
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Example 4: js init array length
new Array(4);