Intent to ship: Array.prototype.{flat,flatMap}

51 views
Skip to first unread message

Mathias Bynens

unread,
May 23, 2018, 11:26:25 AM5/23/18
to blink-dev, v8-users, Benedikt Meurer

Contact emails

mat...@chromium.org, bme...@chromium.org


Spec

https://tc39.github.io/proposal-flatMap/


Summary

A Stage 3 proposal introduces two new array methods.

Array.prototype.flat flattens arrays recursively up to the specified depth, which defaults to 1.

// Flatten one level:
const array = [1, [2, [3]]];
array.flat();
// → [1, 2, [3]]

// Flatten recursively until the array contains no more nested arrays:
array.flat(Infinity);
// → [1, 2, 3]

The same proposal includes Array.prototype.flatMap, which is like Array.prototype.map except it flattens the result into a new array.

[2, 3, 4].flatMap((x) => [x, x * 2]);

// → [2, 4, 3, 6, 4, 8]

Interoperability and compatibility risk

The flat method was originally called flatten, which was found to be not Web-compatible when Firefox shipped it. More recently, flatten was renamed into flat in the hopes of it resolving the compatibility issue.


  • Firefox: Public support (they shipped the proposal in its earlier form, and will now rename)

  • Edge: No public signals

  • Safari: Public support (Safari TP currently has a flatten implementation which they’ll rename)

  • Web developers: Strongly positive


Is this feature fully tested?

Yes; our implementation passes our own V8 tests as well as the Test262 tests for these two features.


Tracking bug

https://bugs.chromium.org/p/v8/issues/detail?id=7220


Link to entry on the Chrome Platform Status dashboard

https://www.chromestatus.com/feature/6629507075145728


Requesting approval to ship?

Yes. Note that since this is a V8/JS feature, this post is just an FYI to blink-dev — no signoff from Blink API owners is required.


Sathya Gunasekaran

unread,
May 29, 2018, 10:22:44 AM5/29/18
to Mathias Bynens, blink-dev, v8-users, Benedikt Meurer
LGTM
On Wed, May 23, 2018 at 11:26 AM Mathias Bynens <mat...@chromium.org>
wrote:
> --
> You received this message because you are subscribed to the Google Groups
"blink-dev" group.
> To view this discussion on the web visit
https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CADizRga6aY7zgR6x-8YuXCBYZGurPSzR9F4_%3DqK%2B7D_ADGY4-Q%40mail.gmail.com
.

Mathias Bynens

unread,
May 29, 2018, 12:02:24 PM5/29/18
to v8-users, blink-dev, Benedikt Meurer
For future reference: this landed in V8 v6.9.* and should thus be available in Chrome 69.



--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages