According to the example provided in the documentation,
let first:number[] = [1, 2];
let second:number[] = [3, 4];
let both_plus:number[] = [0, ...first, ...second, 5];
console.log(`both_plus is ${both_plus}`);
first[0] = 20;
console.log(`first is ${first}`);
console.log(`both_plus is ${both_plus}`);
both_plus[1]=30;
console.log(`first is ${first}`);
console.log(`both_plus is ${both_plus}`);
The concept of Spreading results in a deep copy because each array maintains its own set of values, as shown below:
both_plus is 0,1,2,3,4,5
first is 20,2
both_plus is 0,1,2,3,4,5
first is 20,2
both_plus is 0,30,2,3,4,5
The Documentation states that: Spreading creates a shallow copy of first
and second
. How can we interpret this?