Favorites

JavaScript Array.prototype.flatMap() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.prototype.flatMap()
JavaScript Array Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The flatMap() method maps each element with a function and flattens the result by one level, letting one element become several or none.

Description

The flatMap() method is the same as calling map() followed by flat() with a depth of 1, but slightly more efficient. Because the callback can return an array, each element can produce several elements, one or none in the result.

Returning an empty array removes an element, so flatMap() can filter and map in a single pass.

Only one level is flattened: if the callback returns nested arrays, the inner arrays stay nested in the result. The callback receives the same arguments as map(), the element, its index and the array. A common use is expanding records into several rows, such as turning orders into a flat list of their line items.

Syntax

array.flatMap(callbackFn)
array.flatMap(callbackFn, thisArg)

Parameters

  • callbackFnA function that returns a value or an array of values for each element. It receives element, index and array.
  • thisArgOptional. A value to use as this inside callbackFn.

Return Value

A new array of the callback results, flattened by one level.

Example

const sentences = ['hello world', 'how are you'];
console.log(sentences.flatMap(s => s.split(' ')));

const nums = [1, 2, 3, 4];
console.log(nums.flatMap(n => (n % 2 ? [] : [n, n * 10])));

Browser Support

The following information will show you the current browser support for the Array.prototype.flatMap() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee