When initializing b
, it appears that the array data is being copied from a
instead of referencing it, as originally intended:
let a = [0,1];
let b = [a[0], 2];
a[0]=3;
console.log(b);
The resulting output is 0,2
.
- What is the reason for the output not being
3,2
? - How can the initialization of
b[0]
be set to referencea[0]
in order to reflect changes made toa
? - If this is not possible, what other options are available?
- Is there a specific name for this situation?