0

Is there a way to use a spread operator over another spread operator?

const arr = [[1,2,3],[4],[5,6],[7,8,9]];
const spreadArr = [...arr];  // This works
console.log(spreadArr); // [[1,2,3],[4],[5,6],[7,8,9]]

But, can we somehow chain it like we can over the map, filter or other methods?

With the output to probably spread the 2d-array into a 1-d one. And the code or syntax to be something like:

const doubleSpreadArr = [...(...arr)];
console.log('The expected output to be: ', doubleSpreadArr);
// The output expected to be [1,2,3,4,5,6,7,8,9]

How does the spread operator exactly work in JavaScript(v8, or any other engine)?

Trishant Pahwa
  • 2,024
  • 1
  • 10
  • 29

0 Answers0