1👍
✅
If your object has properties that are "indexes" (numeric strings in range 0 .. 2^32-1), these properties are always enumerated is sorted numeric order. There’s no way you can change that.
Have your server app return data in a more reasonable format, like an array of number-string pairs or an array of objects {id, value}
. If this is not possible, convert your object to the said format on the client side, for example:
response = {753: 'Wraith', 752: 'Phantom Extended', 751: 'Phantom', 750: 'Ghost Extended', 749: 'Ghost', 748: 'Dawn', 747: 'Cullinan', 746: 'Black Badge'}
dataToDisplay = Object.entries(response).sort(
([key1, val1], [key2, val2]) =>
val1.localeCompare(val2))
console.log(dataToDisplay)
Source:stackexchange.com