2024-05-06 20:40:05 +00:00
|
|
|
---
|
2024-10-30 17:34:11 +00:00
|
|
|
date: 2020-10-14
|
2024-05-06 20:40:05 +00:00
|
|
|
id: 981a83a9-9288-400b-a9d7-0f28a3795495
|
|
|
|
title: Spread (…)
|
|
|
|
---
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
|
|
|
|
Math.max() returns the numerically greatest of its arguments. It works
|
|
|
|
for an arbitrary number of arguments, but not for Arrays.
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
console.log(Math.max(...[-1, 5, 11, 3]))
|
|
|
|
```
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
const arr1 = ['a', 'b'];
|
|
|
|
const arr2 = ['c', 'd'];
|
|
|
|
|
|
|
|
arr1.push(...arr2); // arr1 is now ['a', 'b', 'c', 'd']
|
|
|
|
```
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
const arr1 = ['a', 'b'];
|
|
|
|
const arr2 = ['c'];
|
|
|
|
const arr3 = ['d', 'e'];
|
|
|
|
|
|
|
|
console.log([...arr1, ...arr2, ...arr3]); // [ 'a', 'b', 'c', 'd', 'e' ]
|
|
|
|
```
|