Skip to content

Instantly share code, notes, and snippets.

@scazzy
Last active January 28, 2017 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scazzy/47f351f5820bfe7b4266a6259edcc190 to your computer and use it in GitHub Desktop.
Save scazzy/47f351f5820bfe7b4266a6259edcc190 to your computer and use it in GitHub Desktop.
Nested array flatten method
let flattenedArray = [];
const flattn = (arr) => {
for(let i in arr) {
if(typeof arr[i] === 'object' && arr[i].length) {
flattn(arr[i]);
} else {
flattenedArray.push(arr[i]);
}
}
return flattenedArray;
};
export default flattn;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment