Created
September 7, 2016 07:40
-
-
Save sahanDissanayake/02f0b74ee848ef3ab38e79dd7c612fb4 to your computer and use it in GitHub Desktop.
Turn a nested array in to a single array of components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [[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