Array.prototype.toObjectByProperty( element=> )

T.J. Crowder tj.crowder at
Sat Aug 5 11:41:08 UTC 2017

On Sat, Aug 5, 2017 at 12:22 PM, Lachlan Hunt
<lachlan.hunt at> wrote:
> 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.
> That looks like what can already do.

No, the end result is an object, not an array. It probably would have
helped if Naveen had included an example. Here I'm using `Object.from` (see
my previous email) rather than `toObjectByProperty`:

const a = [{id: "tjc", name: "T.J. Crowder"}, {id: "nc", name: "Naveen
Chawla"}, {id: "lh", name: "Lachlan Hunt"}];
const index = Object.from(a);

would yield:

    tjc: {id: "tjc", name: "T.J. Crowder"},
    nc: {id: "nc", name: "Naveen Chawla"},
    lh: {id: "lh", name: "Lachlan Hunt"}

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list