티스토리 뷰
const obj1 = { key: 'key1' };
const obj2 = { key: 'key2' };
const array = [obj1, obj2];
// array copy
const arrayCopy = [...array];
console.log(arrayCopy); // [ { key: 'key1' }, { key: 'key2' } ]
const arrayCopy2 = [...array, { key: 'key3' }];
obj1.key = 'newKey'; // array배열은 래퍼런스 값을 갖고있는 배열이다. 그래서 전개연산자로 복사하여도
// 레퍼런스 변수는 복사로 취급하지만, 그걸 잇는 주소연결은 똑같다.
console.log(array); // [ { key: 'newKey' }, { key: 'key2' } ]
console.log(arrayCopy2); // [ { key: 'newKey' }, { key: 'key2' }, { key: 'key3' } ]
// object copy
const obj3 = { ...obj1 };
console.log(obj3); // { key: 'newKey' }
// array concatenation
const fruits1 = ['🍑', '🍓'];
const fruits2 = ['🍌', '🥝'];
const fruits = [...fruits1, ...fruits2];
console.log(fruits); // [ '🍑', '🍓', '🍌', '🥝' ]
// object merge
const dog1 = { dog: '🐕' };
const dog2 = { dog: '🐶' };
const dog = { ...dog1, ...dog2 };
console.log(dog); // { dog: '🐶' }
'Skill > html js css' 카테고리의 다른 글
js 비구조화할당 destructuring assignment (1) | 2025.02.10 |
---|---|
js 속성 선택자 (0) | 2025.01.03 |
js validation (0) | 2025.01.03 |
inputmask 사용예 (0) | 2025.01.03 |
유용한 js 라이브러리 (0) | 2025.01.03 |
- Total
- Today
- Yesterday
- Keycode
- getter
- PostgreSQL
- springboot
- 프로젝트명변경
- JQuery
- border-collapse
- ul li로 테이블
- Javascript
- QueryDSL
- CSS
- element위치
- $.extend
- draw.io
- object key
- 여러 컬럼 update
- sumifs
- setter
- DatePicker
- devtools
- $.each
- 진열사랑
- @ExceptionHandler
- excel
- lombok
- 전후방탐색
- 정규식
- oracle
- caniuse
- spring
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |