When we use the Constructor new Array()
in ES5
to build a new fix we do the following:
EXAMPLE 1
let elementos = new Array(2);
console.log(elementos[0]);
console.log(elementos[1]);
//ambos console darán undefined
However, what is the problem?
In the previous example, the numeric value that was passed to it is assumed with the length of the array, but each position in the same array has no elements
EXAMPLE 2
let elementos = new Array("alfa");
console.log(elementos[0]); //imprime alfa
console.log(elementos[1]); //imprime undefined
In the previous example the only element passed is not numeric but a text string, which is assumed in the zero position of the array and the next position will be undefined
EXAMPLE 3
let elementos = new Array("alfa", "BETO");
console.log(elementos[0]); //imprime alfa
console.log(elementos[1]); //imprime BETO
In the previous example we have passed two values, not numerical; same that are placed in each position of the arrangement
How do you solve this Array.of()
?