JavaScript配列flatMap
flat

flatMap配列

forEach

map の後に 1 段階平坦化します。

構文

arr.flatMap(callbackFn)

使用例

下記の値を入力するとサンプルに即時反映されます。

const
sentences
words
flatMap
split
console
const sentences = ["Hello World", "Foo Bar"];
const words = sentences.flatMap((s) => s.split(" "));
console.log(words);   // ["Hello", "World", "Foo", "Bar"]