Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ npm run lint
myArray.push('good');
```

- [8.4](#8.4) <a name="8.4"></a> Use the spread operator (`...`) to copy arrays, rather than iterating over the array or using `Array#slice`. If you need subsections of the array, continue to use `Array#slice`.
- [8.4](#8.4) <a name="8.4"></a> Use the spread syntax (`...`) to copy arrays, rather than iterating over the array or using `Array#slice`. If you need subsections of the array, continue to use `Array#slice`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


```javascript
const originalArray = [1, 2, 3];
Expand All @@ -1123,16 +1123,16 @@ npm run lint
const goodNewArray = [...originalArray];
```

- [8.5](#8.5) <a name="8.5"></a> To convert from an array-like object to an array (for example, a `NodeList` returned by `document.querySelectorAll`, or a jQuery object), use `Array.from`.
- [8.5](#8.5) <a name="8.5"></a> To convert from an object that is iterable to an array (for example, a `NodeList` returned by `document.querySelectorAll`, or a jQuery object), use the spread syntax (`...`). For objects without an iteration protocol, continue to use `Array.from`.

```javascript
const nodes = document.querySelectorAll('.my-nodes');

// bad
const badNodesArray = [].slice.apply(nodes);
const badNodesArray = Array.from(nodes);

// good
const goodNodesArray = Array.from(nodes);
const goodNodesArray = [...nodes];
```

[↑ scrollTo('#table-of-contents')](#table-of-contents)
Expand Down Expand Up @@ -1306,7 +1306,7 @@ npm run lint
}
```

- [10.7](#10.7) <a name="10.7"></a> Instead of using `function#apply()` to call a function with an array of arguments, use the spread operator.
- [10.7](#10.7) <a name="10.7"></a> Instead of using `function#apply()` to call a function with an array of arguments, use the spread syntax.

> Why? It reduces redundancy since you don’t have to specify the object to apply against, and it mirrors the rest syntax when declaring variadic functions.

Expand Down