Why can't the spread operator be used multiple times?
let arr = [[[1, 2, 3]]];
console.log(arr); // Array [[[1, 2, 3]]]
console.log(...arr); // Array [[1, 2, 3]]
console.log(...(...arr));
// Uncaught SyntaxError: Unexpected token '...'
I had expected :
console.log(...(...arr)); // Array [1, 2, 3]
...(arr)works. it is the same as...arrarre.g....arr. Withconsole.log(...(...arr));you are attempting to pass a spread operator + assignment expression as an assignment expression to another spread operator. See ecma-international.org/ecma-262/6.0/#sec-argument-listsconsole.log(...[].concat(...arr))(or any otherflattening function)