Created
June 10, 2021 14:40
-
-
Save mirashif/675a25d940e9f2f1b091167a9d39ec1a to your computer and use it in GitHub Desktop.
Here is a quick way to flatten a deeply nested array in Javascript.
This file contains hidden or 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
const nested = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]]; | |
const flatten = nested.flat(Infinity); | |
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
const result = flatten.join(", "); | |
// "1, 2, 3, 4, 5, 6, 7, 8, 9, 10" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment