// '배열형태로 전달'되는 파라미터. (= 가변인자)
function printAll(...args) {
for (let i=0; i<args.length; i++) { // for 반복문 방법1
console.log(args[i]);
}
for (const arg of args) { // for 반복문 방법2
console.log(arg);
}
args.forEach((arg) => console.log(arg)); // 배열 반복출력 함수 - forEach
}
// function printAll(a, b, ...args) {} : 이런 인자 처리도 가능
printAll('dream', 'coding', 'ellie');
// ※주의 : ['dream', 'coding', 'ellie'] 로 변환되어 파라미터로 전달된다.
// -> length : 3
// dream
// coding
// ellie
printAll(['dream', 'coding', 'ellie']);
// ※주의 : [['dream', 'coding', 'ellie']] 로 변환되어 파라미터로 전달된다.
// -> length : 1
// ['dream', 'coding', 'ellie']