mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-29 22:46:22 +00:00
32 lines
501 B
Markdown
32 lines
501 B
Markdown
---
|
|
date: 2020-09-22
|
|
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)
|
|
```
|