Rest Parameters
JS · Variables & Constantssyntax
function fn(...args) {}example
function sum(...numbers) {
return numbers.reduce((total, n) => total + n, 0);
}
console.log(sum(5, 10, 15));output
30Note Rest must be the last parameter. Unlike the old arguments object, rest gives you a real Array with all array methods.