let nestedArr = [[0,0],[0,0]]
let insideArr = nestedArr[0]
let targetArr = [1,1]
Basically I want to change the insideArr's
elements to equal to targetArr
, and it should change the first element of nestedArr
too (because insideArr
is refering to that).
insideArr = targetArr
insideArr = [..targetArr]
Above 2 approaches won't work because it will make insideArr
pointing to new reference.
I know using forEach
to loop through insideArr
and assign it one by one should work, but is there a better way? And BTW, should I avoid this kind of usage?