Tip 31 Pass a Variable Number of Arguments with the Rest Operator

In this tip, you’ll learn to collect an unknown number of parameters with the rest operator.

In the previous tips, you saw how object destructuring would let you combine several parameters into a single argument.

Using objects to hold parameters is a great technique, but it’s really only useful in situations where the parameters are different and you know them ahead of time. In other words, it only makes sense in situations with objects.

That may seem obvious, but it raises the question: How do you handle an unknown number of similar parameters?

Think back to the photo display application. What if you wanted to allow your users to tag photos but you only wanted the tags ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.