I have been trying to sort the json response object array in specific order like if the object contains Umlaute words/characters
object {
item: 1,
users: [
{name: "A", age: "23"},
{name: "B", age: "24"},
{name: "Ä", age: "27"}
]
}
Expected name sorting is A, Ä and B.
when trying to sort with localecompare().
object.sort(function (a, b) { return a.localeCompare(b); });
Getting the error like object.sort is not a function. Is there anyway to sort the object array.
sortis an array method and you can never guarantee the order of object keyssort. Shouldn't you doobject.users.sort((a,b) => a.name.localeCompare(b.name)).