Maps and flattens the result.

Type signature

<T, TResult>(f: (value: T, index: number, context: T[]) => TResult[]) => (xs: T[]) => TResult[]

Examples

flatMap((text) => [...text])([
  "test",
  "123",
]);
// ⇒ ["t", "e", "s", "t", "1", "2", "3"]
Try in REPL

Questions

  • How to flat map an array?
  • How to map and then flatten an array?

TypeScript sourceJavaScript source