I am gettting an api response using axios.
I am sending the api response sorted w.r.t name http://localhost:8000/api/ingredients/ordering=name
The actual object sent is as below from my server.
{
2:{"id":2,"name":"anil"},
1:{"id":1,"name":"sant"},
3:{"id":3,"name":"vino"}
}
or pass the key as string instead of integer
{
"2":{"id":2,"name":"anil"},
"1":{"id":1,"name":"sant"},
"3":{"id":3,"name":"vino"}
}
or key as alphanumeric
{
"a2":{"id":2,"name":"anil"},
"a1":{"id":1,"name":"sant"},
"a3":{"id":3,"name":"vino"}
}
what axios is doing is sorting the objects w.r.t keys and the names are not in sorted order
{
1:{"id":1,"name":"sant"},
2:{"id":2,"name":"anil"},
3:{"id":3,"name":"vino"}
}
or if key is alpha numeric
{
a1:{"id":1,"name":"sant"},
a2:{"id":2,"name":"anil"},
a3:{"id":3,"name":"vino"}
}
How to stop this
I dont want in array format the list because i have to update the individual objects later based on the id. This representation is easy. I am using reactjs state.