Languages
[Edit]
EN

JavaScript - pass unspecified number of arguments to an arrow function

3 points
Created by:
Imaan-Morin
1009

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

Alternative titles

  1. JavaScript - how to pass unknown number of arguments into arrow function
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join