Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flatten a multi dimentional array
const flatten = (...args) => {
let result = [];
args.forEach(arg => {
if (Array.isArray(arg)) {
arg.forEach(element => {
if (Array.isArray(element)) {
result = result.concat(flatten(element));
} else {
result.push(element);
}
});
} else {
result.push(arg);
}
});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.