The following initialization of b seems to copy array data from a instead of referencing it, as intended:
let a = [0,1];
let b = [a[0], 2];
a[0]=3;
console.log(b);
The output is 0,2.
- Why is the output not
3,2? - How can
b[0]be initialized with a reference toa[0]so that it reflects changes toa? - If that's not possible, what are the alternatives?
- Is there a name for this?