[1, [2, [3]]].flat() flattens one level (pass a depth, or Infinity, for deeper). flatMap(fn) is map followed by a one-level flat — handy when each item expands into several (e.g. splitting words from lines) without a separate flatten step.
[1, [2, [3]]].flat() flattens one level (pass a depth, or Infinity, for deeper). flatMap(fn) is map followed by a one-level flat — handy when each item expands into several (e.g. splitting words from lines) without a separate flatten step.
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const lines=['a b','c d']; const words=lines.flatMap(l=>l.split(' '));
document.getElementById('o').textContent=words.join(',');</script></body></html>▶ Open the interactive comic issue