Flatten Nested Array in JavaScript

ArraysRecursion

Implement a function to flatten a nested array in JavaScript.

Examples

Example 1
Input
flattenArray([1, [2, [3, 4], 5], 6]);
Output
[1, 2, 3, 4, 5, 6]
Explanation
The function flattens the nested array.

Constraints

  • The input is a nested array
  • The output is a flattened array

Hints

Read the full write-up for Flatten Nested Array in JavaScript
</>JavaScript
Loading editor…
Test Result
Run your code, or Submit to test it