← Back to release summary

Array.prototype.{flat,flatMap}

Category
JavaScript
Type
New or changed feature
Status
Enabled by default (Chrome 69)
Intent stage
None

Summary

JavaScript arrays are getting two new methods. `Array.prototype.flat()` returns a new array with all sub-array elements concatenated into it recursively up to the specified depth. The sub-array elements become members of the new array. `Array.prototype.flatMap()` first maps each element using a mapping function, then flattens the result into a new array. This method is functionally equivalent to a map followed by a flatten of depth 1.

Standards & signals

Docs: https://v8.dev/features/array-flat-flatmap https://developers.google.com/web/updates/2018/03/smooshgate

View on chromestatus.com