Functions

Rest parameter

Try the free JavaScript compiler

Collects remaining arguments into a genuine array. It must be last, cannot have a default initializer and cannot have a trailing comma. An empty remainder produces an empty array.

Formal Syntax & Structure

javascript syntaxjavascript
function f(first, ...rest) { … }

Working Example

Example Snippetjavascript
function f(first,...rest){return rest.length;}console.log(f(1),f(1,2,3));
JavaScript Reference