Skip to content

Instantly share code, notes, and snippets.

@sahanDissanayake
Created September 7, 2016 07:40
Show Gist options
  • Save sahanDissanayake/02f0b74ee848ef3ab38e79dd7c612fb4 to your computer and use it in GitHub Desktop.
Save sahanDissanayake/02f0b74ee848ef3ab38e79dd7c612fb4 to your computer and use it in GitHub Desktop.
Turn a nested array in to a single array of components
// [[1,2,[3]],4] -> [1,2,3,4]
var unflattenedArray = [[1,2,[3]],4],
flattenedArray = [];
flattenedArray = unflattenedArray.toString().split(',').map(function(arrayItem) {
return parseInt(arrayItem);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment