Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
Archives
Today
Total
관리 메뉴

이글이글

[6] React ES6 Spread Operator 본문

react

[6] React ES6 Spread Operator

suye0n6 2025. 3. 28. 12:01

Spread Operator

JavaScript의 스프레드 연산자( . . . )를 사용하면 기존 배열이나 객체의 전체 또는 일부를 다른 배열이나 객체로 빠르게 복사할 수 있다.

 

const numbersOne = [1, 2, 3];
const numbersTwo = [4, 5, 6];
const numbersCombined = [...numbersOne, ...numbersTwo];

 

스프레드 연산자는 종종 구조 분해와 함께 사용된다.

 

첫 번째와 두 번째 항목을 numbers 변수에 할당하고 나머지는 배열에 넣습니다.

const numbers = [1, 2, 3, 4, 5, 6];

const [one, two, ...rest] = numbers;

 

객체에도 스프레드 연산자를 사용할 수 있다.

const myVehicle = {
  brand: 'Ford',
  model: 'Mustang',
  color: 'red'
}

const updateMyVehicle = {
  type: 'car',
  year: 2021, 
  color: 'yellow'
}

const myUpdatedVehicle = {...myVehicle, ...updateMyVehicle}

'react' 카테고리의 다른 글

[8] React ES6 Ternary Operator  (0) 2025.03.28
[7] React ES6 Modules  (0) 2025.03.28
[5]React ES6 Destructuring  (0) 2025.03.28
[4] React ES6 Array Methods  (0) 2025.03.28
[3]ES6 Variables  (0) 2025.03.28