wiki/content/20200922162500-rest_parameters.md

32 lines
499 B
Markdown

---
date: 20200922
id: 4236e165-bf8b-45fd-9a4c-6cbb66916c45
title: JavaScript Rest Parameters
---
# Introduction
Introduced in [ES6](20201030093404-es6)
# Syntax
``` javascript
function logAllArguments(...args) {
for (const arg of args) {
console.log(arg);
}
}
logAllArguments(1, 2, 3)
```
``` javascript
function logAllArguments(pattern, ...args) {
console.log(pattern)
for (const arg of args) {
console.log(arg);
}
}
logAllArguments("asdf", 1, 2, 3)
```