{
"JsonResult": {
"List": [{
"Subject": "Something",
"Type": 0,
"TypeDescription": "Referral"
}],
}
}
When I hit my service, I receive a sample JSON response. After that, there is a button with options like
Subject, Type, and TypeDescription
.
I am looking for a way to sort the JSON Response based on the parameter I send.
function sortItems(jsonResponse, parameter){
var sorted = jsonResponse.List.sort(function(a, b) {
var nameA = a[parameter].toLowerCase(),
nameB = b[parameter].toLowerCase();
return nameA.localeCompare(nameB);
}
Although this sort function does not seem to be working properly. I already have the JSON response and need to dynamically sort it based on the provided argument.