Javascript rest parameters

Posted by Joe Enos on April 25, 2021 · 1 min read
// collects parameters and turns them into an array
// must be the last parameter
// no IE support
// no Safari support

function writeArguments(name, ...values) {
console.log(`my name is ${name}`);
console.log(JSON.stringify(values)); // [1,2,3]
}

writeArguments("john doe", 1, 2, 3);