You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-5Lines changed: 21 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -364,15 +364,31 @@ Other Style Guides
364
364
```
365
365
366
366
<a name="arrays--from"></a><a name="4.4"></a>
367
-
- [4.4](#arrays--from) To convert an array-like object to an array, use [Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
367
+
- [4.4](#arrays--from) To convert an array-like object to an array, use spreads `...` instead of[Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
368
368
369
369
```javascript
370
370
const foo = document.querySelectorAll('.foo');
371
+
372
+
// good
371
373
const nodes = Array.from(foo);
374
+
375
+
// best
376
+
const nodes = [...foo];
377
+
```
378
+
379
+
<a name="arrays--mapping"></a>
380
+
- [4.5](#arrays--mapping) Use [Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables, because it avoids creating an intermediate array.
- [4.5](#arrays--callback-return) Use return statements in array method callbacks. It’s ok to omit the returnif the function body consists of a single statement returning an expression without side effects, following [8.2](#arrows--implicit-return). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return)
391
+
- [4.6](#arrays--callback-return) Use return statements in array method callbacks. It’s ok to omit the returnif the function body consists of a single statement returning an expression without side effects, following [8.2](#arrows--implicit-return). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return)
376
392
377
393
```javascript
378
394
// good
@@ -420,8 +436,8 @@ Other Style Guides
420
436
});
421
437
```
422
438
423
-
<a name="arrays--bracket-newline"></a>
424
-
- [4.6](#arrays--bracket-newline) Use line breaks after open and before close array brackets if an array has multiple lines
439
+
<a name="arrays--bracket-newline"></a>
440
+
- [4.7](#arrays--bracket-newline) Use line breaks after open and before close array brackets if an array has multiple lines
0 commit comments