Accessing (n)th key from an object
dteller at mozilla.com
Tue Apr 24 15:06:06 UTC 2018
Doing this sounds pretty fragile. Do you have any guarantee that the
order of fields is the same as the order of the array? Even if that's
the case in your scenario, it's pretty uncommon.
On 24/04/2018 16:41, somonek wrote:
> The use case is:
> (long story short)
> I have an array of items coming from an api. They're converted to an
> object having the ids as keys for faster access of single items and
> loaded to a global store.
> Then in React.js and I want to render only the first 2 items with a "See
> more" that would render the rest of them.
> It would be handy (and probably more performant when the object is big
> as in my case) to have:
> const product1 = myItems[in 0];
> const product2 = myItems[in 1];
> instead of converting everything to an array first and then accessing
> the first items by index.
More information about the es-discuss