Создайте массив JavaScript
[...Array(10).keys()]
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Gorgeous Goosander
[...Array(10).keys()]
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.from(Array(10).keys())
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// Don't need to provide elements directly, but you can
// FIRST OPTION
var myArray = new Array(/*elements1, elements2*/);
// SECOND OPTION
var mySecondArray = [/*element1, element2*/];
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
const array1 = ["eat", "sleep"];
// Ways to create an array in javascript
const stuff = [element1, element2, ...]; // array literal notation
const stuff = new Array(element1, element2, ...); // array object notation