DEV Community

Discussion on: Celebrating JavaScript .flat()

Collapse
 
devtrong profile image
Trong Nguyen

Nice read :) As an additional alternative, i've always used Set to flatten my arrays.

const arr = ['carrot cake', 'birthday cake', ['cheesecake', 'chocolate cake']];
console.log([].concat(...new Set(arr)));
Collapse
 
katkelly profile image
Katherine Kelly

Using a Set is a great alternative!