mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 11:36:23 +00:00
32 lines
499 B
Markdown
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)
|
|
```
|