Array.prototype.toObjectByProperty( element=>element.property )
Lachlan Hunt
lachlan.hunt at lachy.id.au
Sat Aug 5 11:22:40 UTC 2017
On 2017-08-05 20:18, Naveen Chawla wrote:
> I've often needed to cache array elements by a unique key each element has,
> for quick access.
>
> This is a shortcut:
>
> ```javascript
> const elementsById = elements.toObjectByProperty(element=>element.id);
> ```
That looks like what Array.prototype.map can already do.
--
Lachlan Hunt
https://lachy.id.au/
More information about the es-discuss
mailing list