Skip to content

Commit 844adc3

Browse files
committed
Merge pull request DrkSephy#56 from ipeters90/master
Adding more documentation to spread operators
2 parents 0b8918a + 62f04b4 commit 844adc3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,25 @@ function initializeCanvas(
576576

577577
### Spread Operator
578578

579-
We can use the spread operator to pass an array of values to be used as
579+
In ES5, we could find the max of values in an array by using the `apply` method on `Math.max` like this:
580+
```javascript
581+
Math.max.apply(null, [-1, 100, 9001, -32]); // 9001
582+
```
583+
584+
In ES6, we can now use the spread operator to pass an array of values to be used as
580585
parameters to a function:
581586

582587
```javascript
583588
Math.max(...[-1, 100, 9001, -32]); // 9001
584589
```
585590

591+
We can concat array literals easily with this intuitive syntax:
592+
593+
```javascript
594+
let cities = ['San Francisco', 'Los Angeles'];
595+
let places = ['Miami', ...cities, 'Chicago']; // ['Miami', 'San Francisco', 'Los Angeles', 'Chicago']
596+
```
597+
586598
<sup>[(back to table of contents)](#table-of-contents)</sup>
587599

588600
## Classes

0 commit comments

Comments
 (0)