DEV Community

loading...

Discussion on: Don’t pay the for-loop tax

Collapse
mike1808 profile image
Michael Manukyan

Never rely on the order of keys of objects in JavaScript because by specification the interpretator can order them as it wishes

Collapse
julienetienne_ profile image
Wolfie's just fine

Not for generic prop names but if you previously "created" incremental prop names:

const obj = {thing-0: 'thing-a', another-thing-1: 'thing-b', 'something-2: 'thing-c'};
...
... obj[key.value.slice(0,-1) + i] // do something

There could also be situations where you need to accumulate based on the number of props rather than specifically the order of props.