JavaScript: Flatten an array recursively
19 February 2023 (Updated 12 April 2025)
[2, 4, [5, [6, [7, [8]]]]].flat(Infinity)
// => [2, 4, 5, 6, 7, 8]
Tagged:
JavaScript recipes
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment