Skip to main content Accessibility Feedback

Variables & Functions

Rest Parameters

Define rest parameters by creating a parameter prefixed with .... Any arguments provided at or beyond the rest parameter on a function get combined into an array that’s assigned to the rest parameter’s name.

In the example below, ...moreArgs is a rest parameter.

function logStuff (arg1, arg2, ...moreArgs) {

	// Logs arg1

	// Logs arg2

	// Logs an array of any other arguments you pass in after arg2


// In this example...
// arg1 = 'chicken'
// arg2 = 'tuna'
// moreArgs = ['chips', 'cookie', 'soda', 'delicious']
logStuff('chicken', 'tuna', 'chips', 'cookie', 'soda', 'delicious');

Find this useful? You can support my work by purchasing an annual membership.