Spread operator
Destructuring
const [a, b, c] = 'abc';
c
'c'
const [first, ...rest] = [1, 2, 3];
first
1
rest
[2, 3]
Spreading Arguments
const nums = [1, 2, 3];
Math.max(...nums);
3
Array Concatenation
const abc = ['a', 'b', 'c'];
const def = ['d', 'e', 'f'];
[...abc, ...def];
['a', 'b', 'c', 'd', 'e', 'f']
The spread operator only requires that the values are iterable. We don't have to use arrays.
const hij = ['h', 'i', 'j'];
const klm = 'klm';
[...hij, ...klm];
['h', 'i', 'j', 'k', 'l', 'm']