JavaScript 2025 · Arrays

Map and flatten in one step

Collect the tags of every post into a single array.

const tags = posts.flatMap((post) => post.tags);

Official JavaScript 2025 documentation

More arrays commands

All arrays commands · JavaScript 2025 cheatsheet

Was this page helpful?