티스토리 뷰
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: '🐶' }
var 키워드로 선언한 변수는 중복선언이 가능하다.
let, const로 선언한 변수는 중복 선언이 불가능하다.
'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
- Javascript
- element위치
- CSS
- $.each
- $.extend
- oracle
- spring
- sumifs
- excel
- devtools
- @ExceptionHandler
- Keycode
- ul li로 테이블
- border-collapse
- JQuery
- 프로젝트명변경
- springboot
- QueryDSL
- draw.io
- 여러 컬럼 update
- lombok
- caniuse
- getter
- 전후방탐색
- object key
- 진열사랑
- setter
- DatePicker
- 정규식
- PostgreSQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |