// ...[1, 2, 3]은 배열 [1, 2, 3]을  개별적인 항목(1 2 3)으로 분리한다.
console.log(...[1, 2, 3]); // 출력: 1 2 3

// 문자열은 순회 가능한 iterable이다.
console.log(..."Hello World"); // 출력: "H e l l o   W o r l d"

// Map과 Set
console.log(...new Map([["apple", "red"], ["banana', "yellow"]])); // 출력: ['apple', 'red'] ['banana', 'yellow']
console.log(...new Set(["a", "b", "c"])); // 출력: "a b c"

// function의 arguments
function fn(arg1, arg2, arg3) {
    console.log(...arguments);
};

fn("arg_1", "arg_2", "arg_3"); // 출력: "arg_1 arg_2 arg_3"
<!DOCTYPE html>
<html lang="ko">
    <head>
        <meta charset="UTF-8">
        <title>NodeList</title>
        
    </head>
    <body>
        <ul>
            <li>김밥</li>
            <li>라면</li>
            <li>떡볶이</li>
        </ul>
        <script src="test.js"></script>
    </body>
</html>
const nodeLi = document.getElementsByTagName("li");
const arr = [...nodeLi];

arr.forEach((li, index) => {
    console.log(`Item ${index + 1}: ${li.textContent}`);
});

/*
    출력:
    "Item 1: 김밥"
    "Item 2: 라면"
    "Item 3: 떡볶이"
*/
console.log(...{name: "홍길동", age: 24}); // Uncaught TypeError
const obj1 = {x: 1, y: 2};
const obj2 = {z: 3};
const mergedObject = {...obj1, ...obj2};

console.log(mergedObject); // 출력: {x: 1, y: 2, z: 3}
const items = ...[1, 2, 3, 4]; // Uncaught SyntaxError
const myIfStatement = if (condition) { // Uncaught SyntaxError
    // some code here
 };
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]
const obj1 = {x: 1, y: 2};
const obj2 = {z: 3};

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

// 새 속성을 추가하면서 객체를 확장
const extendedObject = {...obj1, a: 4};
console.log(extendedObject); // 출력: {x: 1, y: 2, a: 4}
function sum(a, b, c) {
    return (a + b + c);
}
  
const numbers = [1, 2, 3];
  
const result = sum(...numbers); // sum(1, 2, 3)과 동일한 결과를 반환
// HTMLCollection 가져오기 (예: 모든 <p> 요소)
const paragraphs = document.getElementsByTagName("p");

// HTMLCollection을 배열로 변환하여 스프레드 문법을 사용하여 병합
const paragraphArray = [...paragraphs];
const combinedArray = [1, 2, 3, ...paragraphArray];
브라우저별 호환(지원)에 대한 표입니다.
속성
데스크탑 Chrome
Chrome
데스크탑데스크탑 Edge
Edge
데스크탑 Firefox
Firefox
Safari
Safari
스프레드 문법 46 12 16 8

caniuse.com에서 더 자세한 정보를 확인해 보세요.