I just found something is interesting in Javascript multidimensional array.
let arr = Array(3).fill([]);
arr[0].push('1');
I thought the result should be arr = [['1'], [], []]
, but got arr = [['1'], ['1'], ['1']]
.
If update a value as arr[2][0] = '*'
, expected array to be arr = [['1'], ['1'], ['*']]
, but got arr = [['*'], ['*'], ['*']]
.
So why Javascript multidimensional array work like this? How to just update a value in multidimensional array?