Javascript doesn't support multidimensional arrays the way you're thinking of them; each element of an array can be another array, but they're not required to be as in a true multidimensional array in other languages. (The same goes for array length; the boundaries of the array aren't predefined as they are in some other languages.)
To correct your code, all you'd need to do is declare that each element of quinielas
is itself a new Array.
let quinielas = new Array(20);
function generaResultados(quinielas) {
for (let i = 0; i < quinielas.length; i++) {
quinielas[i] = new Array(20); // <-- add this
for (let j = 0; j < quinielas[i].length; j++) {
quinielas[i][j] = "something";
}
}
console.log(quinielas);
}
generaResultados(quinielas);
(Note though that the parameter in new Array()
is a bit ambiguous and should probably be avoided; it does set what .length
will return, but otherwise doesn't behave as you'd expect. All the elements are still undefined, and logging the array itself still just returns []
just as if you had omitted the param. (This was a bit of a "today I learned" for me; up until now, after decades of coding in JS, I had been under the impression that new Array()
and new Array(20)
gave identical results.)