json.parse(json.stringify())1 ... (Spread Operator)로 얕은 복사(Shallow Copy)하기 스프레드 연산자는 얕은 복사를 수행한다.하지만, 모든 값이 복사되는 방식이 다름!Primitive 타입(원시값) → 새로운 값이 복사됨Object 타입 (참조값) → 기존 객체의 참조(reference) 가 복사됨코드 실행 결과const test = { name: "bob", profile: { email: "test@", },};// 얕은 복사 (Shallow Copy)const test2 = { ...test };test2.name = "w"; // (1) 새로운 값으로 변경test2.profile.email = "changed@"; // (2) 중첩 객체 내부 값 변경console.log(test); // 원본 객체console.log(test2); // 복사된 객체출력 결과// 원본 .. 2025. 3. 18. 이전 1 다음