wiki/content/20200922162500-rest_parameters.md

499 B

date id title
20200922 4236e165-bf8b-45fd-9a4c-6cbb66916c45 JavaScript Rest Parameters

Introduction

Introduced in ES6

Syntax

function logAllArguments(...args) {
    for (const arg of args) {
        console.log(arg);
    }
}

logAllArguments(1, 2, 3)
function logAllArguments(pattern, ...args) {
    console.log(pattern)
    for (const arg of args) {
        console.log(arg);
    }
}

logAllArguments("asdf", 1, 2, 3)