EN
JavaScript - pass unspecified number of arguments to an arrow function
3
points
In this article, we would like to show you how to pass an unspecified number of arguments to an arrow function in JavaScript.
The below example presents how to do this using spread syntax (...
).
That syntax lets the programmer use all function arguments like an array of arguments.
// ONLINE-RUNNER:browser;
const printLog = (...args) => {
for (let i = 0; i < args.length; ++i) {
console.log(args[i]);
}
};
printLog('a', 'b', 'c');
Output:
a
b
c