I am fetching data from a rest endpoint in my node.js application.
w can I sort the results since I cannot modify the rest server to provide sorted data to begin with?
I have spent a lot of time googling for ways to sort json data and also how to convert json to an array then sort the array then convert the results back to json format for the observableArray to use without any success.
The data retrieved is unsorted, but I want to present it in sorted in a table using knockout data-bindings.
My fetch code is as follows:
self.searchArray = ko.observableArray();
fetch(http://example.com/users)
.then(res => res.json()) // expecting a json response
.then(json => {
self.searchArray(json.users);
})
.catch(err => {
console.log("an error occurred during the fetch:");
console.log(err);
});
}
I have spent a lot of time googling for ways to sort json data and/or convert the json to an array and sort the array then convert the data back into something that knockout can use without success.