Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
The rest parameter syntax allows a function to accept an indefinite number of arguments as an array, providing a way to represent variadic functions in JavaScript.
There are some additional syntax restrictions:
A function definition's last parameter can be prefixed with ... (three U+002E FULL STOP characters), which will cause all remaining (user supplied) parameters to be placed within an Array object.
The rest parameter may be destructured, which allows you to ignore certain parameter positions.
However, the following are all syntax errors:
The rest parameter is not counted towards the function's length property.
There are four main differences between rest parameters and the arguments object:
In this example, the first argument is mapped to a and the second to b, so these named arguments are used as normal.
However, the third argument, manyMoreArgs, will be an array that contains the third, fourth, fifth, sixth, …, nth — as many arguments as the user specifies.
Below, even though there is just one value, the last argument still gets put into an array.
Below, the third argument isn't provided, but manyMoreArgs is still an array (albeit an empty one).
Below, only one argument is provided, so b gets the default value undefined, but manyMoreArgs is still an empty array.
Since theArgs is an array, a count of its elements is given by the length property. If the function's only parameter is a rest parameter, restParams.length will be equal to arguments.length.
In the next example, a rest parameter is used to collect all parameters after the first parameter into an array. Each one of the parameter values collected into the array is then multiplied by the first parameter, and the array is returned:
Array methods can be used on rest parameters, but not on the arguments object:
Rest parameters were introduced to reduce the boilerplate code that was commonly used for converting a set of arguments to an array.
Before rest parameters, arguments need to be converted to a normal array before calling array methods on them:
Now, you can easily gain access to a normal array using a rest parameter:
| ECMAScript® 2027 Language Specification # sec-function-definitions |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.