Suggestions for Set

Domenic Denicola domenic at domenicdenicola.com
Mon Oct 1 20:46:26 PDT 2012


-----Original Message-----
From: es-discuss-bounces at mozilla.org [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Brendan Eich
Sent: Monday, October 1, 2012 21:43
To: Nicholas C. Zakas

> > I would really like to see a *Set.prototype.toArray* method to easily change the Set back into an array. A simple use case would be de-duping an array:
> >
> >     function dedupe(array) {
> >         return (new Set(array)).toArray();
> >     }
> >
> >
>
> Array.from is the way we hope to avoid burdening many iterables with "toArray" methods, as Rick pointed out. Ok?

Also:

function dedupe(array) {
    return [...new Set(array)];
}

This works in Firefox Aurora, for the record :)



More information about the es-discuss mailing list