I get strange results in my code.
function myFunction() {
var arrT = new Array(2)
arrT.fill('-');
var arrR = new Array(4);
arrR.fill(arrT);
console.log(arrR); // returns [ [ '-', '-' ], [ '-', '-' ], [ '-', '-' ], [ '-', '-' ] ]
arrR[0][1]='xxx'
console.log(arrR); // returns [ [ '-', 'xxx' ], [ '-', 'xxx' ], [ '-', 'xxx' ], [ '-', 'xxx' ] ]
}
I need a prefilled 2D-array (here I define it fixed but normally the dimension is calculated) I thought I use the fill method and it seemed to work fine. but when I try to put a value in a cell, all rows are filled.
What i'm doing wrong? I expected to have [ [ '-', 'xxx' ], [ '-', '-' ], [ '-', '-' ], [ '-', '-' ] ]
Many thanks in advance,
Filip