On Sat, Aug 5, 2017 at 12:22 PM, Lachlan Hunt
<lachlan.h...@lachy.id.au> 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 Array.prototype.map 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`:

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

would yield:

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

-- T.J. Crowder
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to