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. On Tue, Apr 24, 2018 at 4:18 PM, T.J. Crowder < tj.crow...@farsightsoftware.com> wrote: > On Tue, Apr 24, 2018 at 2:54 PM, somonek > <somo...@gmail.com> wrote: > > ... > > > > could > > myObject[in 0] === 'one' // true > > What's the use case? Relying on the order of the properties in the object > is almost always a bad idea (although if I read the current spec correctly, > `Object.keys` is no longer exempt from order as it once was). The only time > I've seen this done that seemed reasonable was when the object was known to > have a single own enumerable property but that property's name was unknown > (which was, in itself, an X/Y problem -- the real problem was why that name > was unknown/varied at runtime). > > -- T.J. Crowder >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss