I'm looking for an implementation of createEmpties(nValues)
as below:
var result = createEmpties(4);
console.log(result)
[[], [], [], []]
I tried using map:
new Array(nValues).map(_ => []);
but got this output:
[ <4 empty items> ]
I'm looking for an implementation of createEmpties(nValues)
as below:
var result = createEmpties(4);
console.log(result)
[[], [], [], []]
I tried using map:
new Array(nValues).map(_ => []);
but got this output:
[ <4 empty items> ]
The new Array, will not fill. Try Array(nValues).fill(null).map(_ => []). This should give you what you are looking for.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill