On this page
  1. Array.flatMap
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

Array.flatMap

Prev: find | Up: Array | Next: includes
Rel: Array, Array & Typed Arrays Guide
Ref: MDN Web Docs — Array.flatMap
Tags: #public #web #javascript #builtins #array #tier/core


Signature & Overview

arr.flatMap(fn)

Maps each element and flattens the result by one level in a single pass.

Notes & Pitfalls

Example

const lines = ["hello world", "js rocks"];
const words = lines.flatMap((line) => line.split(" "));
console.assert(words.length === 4 && words[2] === "js");

Linked from

Related notes