Files
freeCodeCamp/guide/chinese/javascript/es6/spread-operator/index.md
2018-10-16 21:32:40 +05:30

23 lines
611 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Spread Operator
localeTitle: 传播运营商
---
## 传播运营商
扩展运算符( `...` )允许获取集合的元素。
最常见的用途之一是`Node` Objects当在浏览器中使用查询选择器时为了使它们成为可迭代的数组对象
```javascript
const paragraphs = document.querySelectorAll('p.paragraph');
const arr = [...paragraphs];
```
扩展运算符的另一个用途是用于数组连接:
```javascript
const arr_1 = [1, 2, 3, 4]
const arr_2 = [5, 6, 7, 8]
const arr_final = [...arr_1, ...arr_2]
// arr_final = [1, 2, 3, 4, 5, 6, 7, 8]
```