프로그래밍 언어와 기술/JavaScript

[JavaScript] 전개 연산자

tero1115 2023. 7. 11. 15:53

전개 연산자

 - 배열이나 객체의 요소를 뿌린다

    const intArray = [10, 20, 30];

    const secondArray = [...intArray,40];
    console.log(secondArray);

 - 요소 추가하기

    const obj = {
        name : "홍길동",
        age : 12
    }

    const secondObj = {...obj, hobby : "야구"}
    console.log(secondObj);

 

 - 덮어씌우기

    const thirdObj = {...obj, age : 20}
    console.log(thirdObj);

 - 구조 분해 할당

    const { name, ...remainObj } = secondObj;
    console.log(remainObj);