Flattens the nested arrays by a single level.

Type signature

(xs: any) => any[]

Examples

flatten([1, [2, 3], 4, [5, 6]]);
// ⇒ [1, 2, 3, 4, 5, 6]
Try in REPL
flatten([
  1,
  [2, [3, 6]],
  4,
  [5, 6],
]);
// ⇒ [1, 2, [3, 6], 4, 5, 6]
Try in REPL

Questions

  • How to flatten an array?

TypeScript sourceJavaScript source