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