/* 배열 */
const arr = [1, 2, 3];
console.log(...arr); // 출력: 1 2 3

/* 문자열 */
const str = "Hello World";
console.log(...str); // 출력: "H e l l o   W o r l d"

/* DOM 컬렉션 */
const items = document.querySelectorAll(".item"); // NodeList 반환
const itemsArray = [...items]; // 스프레드 구문을 사용하여 배열로 변환

// 이제 배열 메서드를 사용할 수 있음
itemsArray.forEach(item => {
    console.log(item.textContent);
});
const arr1 = [1, 2];
const arr2 = [3, 4];
const mergedArr = [...arr1, ...arr2];  // 배열 병합

console.log(mergedArr);  // [1, 2, 3, 4]
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];

// 두 배열을 병합
const mergedArray = [...arr1, ...arr2];
console.log(mergedArray); // 출력: [1, 2, 3, 4, 5, 6]

// 새 요소를 추가하면서 배열을 확장
const extendedArray = [...arr1, 4, 5];
console.log(extendedArray); // 출력: [1, 2, 3, 4, 5]
function sum(a, b, c) {
    return (a + b + c);
}
  
const numbers = [1, 2, 3];
  
const result = sum(...numbers); // sum(1, 2, 3)과 동일한 결과를 반환
console.log(result); // 출력: 6
// HTML 문서에 있는 .item 클래스를 가진 모든 요소를 선택
const items = document.querySelectorAll(".item");  // NodeList 반환

// 스프레드 구문을 사용해 NodeList를 배열로 변환
const itemsArray = [...items];  

// 이제 itemsArray는 배열로 변환되었기 때문에 배열 메서드를 사용할 수 있습니다.
itemsArray.forEach(item => {
    console.log(item.textContent);  // 각 .item 요소의 텍스트 내용을 출력
});

// 다른 배열과 병합하기
const newItems = ["New Item 1", "New Item 2"];
const allItems = [...itemsArray, ...newItems];  // 기존 NodeList와 새 배열 병합

console.log(allItems);  // NodeList + 새로운 배열
const items = ...[1, 2, 3, 4]; // Uncaught SyntaxError
const obj = {
    a: 1,
    b: 2,
    c: 3
}

console.log(...obj); // Uncaught TypeError
const obj1 = {
    x: 1,
    y: 2
}

const obj2 = {
    z: 3
};

// 객체 병합
const mergedObj = {...obj1, ...obj2};
console.log(mergedObj);  // { x: 1, y: 2, z: 3 }