Skip to content

Instantly share code, notes, and snippets.

@mrizwanghuman
mrizwanghuman / Flatten-array
Created Jun 22, 2017
Flatten an array of arbitrarily nested arrays
View Flatten-array
var unflatten =[[1,2,[3]],4]
let flatten = (flattenArray) => flattenArray.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [])
console.log(flatten(unflatten));