Skip to content

Instantly share code, notes, and snippets.

@NoahDragon
Last active September 1, 2016 01:35
Show Gist options
  • Save NoahDragon/24498e39664416d2d4346c74060668ae to your computer and use it in GitHub Desktop.
Save NoahDragon/24498e39664416d2d4346c74060668ae to your computer and use it in GitHub Desktop.
var result = [];
function isArray (value) {
return value.constructor === Array;
}
function extract (value) {
if (isArray(value)) {
value.forEach(function (each) {
if (isArray(each)) extract(each);
else result.push(each);
});
} else result.push(value);
return result;
}
console.log(extract([["a", 2, [3, "mn"], "bu"], "la", [12, 34, "ab"]]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment