Spread syntax with arrays
basically
- expands the items of an array by prefixing it with
...
- an empty array expanded is no item
is (in a way) the opposite to the rest syntax
- both use
...
to either expand all items and collect them
- rest syntax must be last in an array, spread can be used in any place
used as function parameter
- prefix with
...
to spread as function params
- pass an array of numbers to Math.max()
used as constructor parameter
- just like in a function call (is not possible using
apply
)
Links
mdn
docs
Syntax docs on MDN.