December 05, 2021
참조 할당, 얕은 복사, 깊은 복사에 관해…
참조 할당
얕은 복사 (Shallow Copy)
깊은 복사 (Deep Copy)
example 1
const arr1 = [{num: 1}, {num: 2}];
const arr2 = arr1;
const arr3 = [1, 2, 3];
const arr4 = arr3;
example 2
const arr1 = [{num: 1}, {num: 2}];
const arr2 = [...arr1];
example 3
const arr1 = [{num: 1}, {num: 2}];
const arr2 = JSON.parse(JSON.stringify(arr1));
example 4
const arr1 = [1, 2];
const arr2 = [...arr1];