Buat nomor javascript array
[...Array(5).keys()];
=> [0, 1, 2, 3, 4]
Gifted Gorilla
[...Array(5).keys()];
=> [0, 1, 2, 3, 4]
Array.from(Array(10).keys())
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
var foo = new Array(45); // create an empty array with length 45
for (i of range(1, 5)) {
console.log(i);
}
/* Output
* 1 2 3 4 5 */
[...range(1, 5)] // [1, 2, 3, 4, 5]
Array.from({length: 10}, (_, i) => i + 1)
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const arr = [...Array(2)] // output [undefined, undefined]