I have an indexed object and need to sort it by alphabetic value. I tried sort()
function but it remove the given indexes and assign new indexes starting from 0, and I want to keep the existing indexes but just sort by the value.
Here is my code.
var response = {3: 'Ab', 8: 'Fe', 10: 'Bc', 15: 'Eg'};
var sorted = Object.values(response).sort();
sorted output = {Ab, Bc, Eg, Fe}
but I don't want to change the existing indexes of each value.
I need to sort the object like this.
var sorted = {3: 'Ab', 10: 'Bc', 15: 'Eg', 8: 'Fe'};