Why does Object.keys return an Array instead of a Set?

Ehab Alsharif ehalsharif92 at gmail.com
Sun Oct 18 15:27:54 UTC 2020


Other than the fact that Object.keys existed really before Sets, you are
comparing apples and oranges here in your benchmarks.
the include method has to scan the array in order to find elements, but
sets are objects which are just hash tables.
Also you typically don't get the keys array to check that a key is there,
you can do that directly using the object you have.
Another thing is that the typical use case for Object.keys is to get an
iterator over the keys, returning a set for that purpose does not serve
that purpose directly.

On Sat, Oct 17, 2020 at 4:51 AM #!/JoePea <joe at trusktr.io> wrote:

> Sets are faster, even for tiny lists of four items. See the perf tests
> (tested in Chrome):
>
> https://twitter.com/trusktr/status/1315848017535098880
>
> https://twitter.com/trusktr/status/1317281652540731392
>
> #!/JoePea
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20201018/0397b9a0/attachment.html>


More information about the es-discuss mailing list