freeCodeCamp/guide/chinese/javascript/es6/spread-operator/index.md

23 lines
611 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
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]
```