I have the following json object and I'm trying to sort it by price.
var data = {"PROPERTY":[
{"PRICE":456,"NAME":"Test Property 1"},
{"PRICE":789,"NAME":"Test Property 2"},
{"PRICE":123,"NAME":"Test Property 3"},
{"PRICE":654,"NAME":"Test Property 4"},
{"PRICE":125,"NAME":"Test Property 5"}
]}
Here is the code i'm using to sort.
data.sort(sortByProperty('PRICE'));
function sortByProperty(property) {
'use strict';
return function (a, b) {
var sortStatus = 0;
if (a[property] < b[property]) {
sortStatus = -1;
} else if (a[property] > b[property]) {
sortStatus = 1;
}
return sortStatus;
};
}
Needless to say the sort is not working. Is it because of the property attribute?