xxxxxxxxxx
function solution(size) {
return Array(size).fill(1);
}
xxxxxxxxxx
let arr = new Array(element0, element1, , elementN)
let arr = Array(element0, element1, , elementN)
let arr = [element0, element1, , elementN]
xxxxxxxxxx
Array.from({length: 10}, (_, i) => i + 1)
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
xxxxxxxxxx
let fruits = ['Apple', 'Banana']
console.log(fruits.length)
// 2
xxxxxxxxxx
// 'fruits' array created using array literal notation.
const fruits = ['Apple', 'Banana'];
console.log(fruits.length);
// 2
// 'fruits2' array created using the Array() constructor.
const fruits2 = new Array('Apple', 'Banana');
console.log(fruits2.length);
// 2
// 'fruits3' array created using String.prototype.split().
const fruits3 = 'Apple, Banana'.split(', ');
console.log(fruits3.length);
// 2
xxxxxxxxxx
// Ways to create an array in javascript
const stuff = [element1, element2, ]; // array literal notation
const stuff = new Array(element1, element2, ); // array object notation