Rest Parameters
Added in ES 2015
The Rest Parameter syntax allows a function to accept any number of arguments as an array.
This syntax is represented by three dots (...) which is the same syntax as the spread operator.
function MyFunction(...myArgs) {
return myArgs.reduce((previous, current) => {
return previous + current;
});
}
console.log myFunction(1,2,3,4) // 10
console.log myFunction(4,5,6,7) // 22
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext