Files
30-seconds-of-code/snippets/flatten-array.md
Soorena 280cefb801 Update flatten-array.md
add closing bracket to the comment part
2017-12-13 00:56:44 +03:30

214 B

Flatten array

Use reduce() to get all elements inside the array and concat() to flatten them.

const flatten = arr => arr.reduce( (a, v) => a.concat(v), []);
// flatten([1,[2],3,4]) -> [1,2,3,4]