I'm using redux and a piece of my state has this structure:
{cityId: {name:cityName, population: numberOfPeople}}
something like:
{
1324:{name:"Clagary", population:1234, id: 1324},
46283: {name:"Edmonton", population: 5678, id: 46283}
}
Everything was fine till i needed to show them in a list with the same order that they have on the main object. At this point, I figured out that objects will auto-sort the keys if they are numbers. I tried to change them to string by putting them inside a "" but it didn't work ({"1324":{...}})
.
So i tried adding and underline character as:
({"_1324":{...}})
Now it's working but I just have to double-check with some of you experts here to make sure that this is a good practice and it's normal to do it this way or if there is any better way to deal with numbers as keys in an object when the order matters.
So I'm asking react/redux experts to see if they would move to other solutions when they need the order or would just do what i did.
P.S. I really don't want to go back to use an array as this type of object store is much easier and handy for us in many ways.