Array.prototype.toObjectByProperty( element=>element.property )

Naveen Chawla naveen.chwl at gmail.com
Tue Aug 8 04:24:35 UTC 2017


On Tue, 8 Aug 2017 at 03:28 Logan Smyth <loganfsmyth at gmail.com> wrote:

> > Object entries() is another strange case. Iterating over Object.keys
> with key=> leaves myObject[key] to access the value, whereas iterating over
> Object.entries with entry=> requires entry[0] and entry[1] which seems more
> verbose for access, and less readable! So do you know why this was
> introduced?
>
> Keep in mind that the pair syntax plays quite nicely with destructuring,
> so assuming the iteration you're describing is something like
>
> ```
> for (const key of Object.keys(myObject)) {
>   const value = myObject[key];
>
>   // do stuff
> }
> ```
>
> I at least think it's much more readable to do
>
> ```
> for (const [key, value] of Object.entries(myObject)) {
>
>   // do stuff
> }
> ```
>
>
Yes unfortunately this doesn't apply to `forEach`, which I use much more
frequently because it allows chaining after `map`, `filter`, `sort`,
`concat` etc. and because it's slightly less verbose. I only use `for..of`
when I need to break out of a loop, and which frankly I'll stop using
once/if `takeWhile`/`skipWhile` are introduced.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170808/66d260ca/attachment.html>


More information about the es-discuss mailing list