이글이글
[6] React ES6 Spread Operator 본문
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 |