my json looks like this:
[
{
"cash": 100,
"uid": "LHy2qRGaf3nkWQgU4axO",
"name": "test2"
},
{
"cash": 1000000,
"uid": "01wFhCSlnd9vSDY4NIkx",
"name": "test"
},
{
"cash": 500,
"uid": "PBOhla0jPwI4PIeNmmPg",
"name": "test3"
}
]
I'm trying to sort the json by the user cash. So what I did is :
var objArr = []; // the json array
function compare(a, b) {
console.log("a" + a.cash);
console.log("b" + b.cash);
if (a.cash > b.cash)
return -1;
if (a.cash < b.cash)
return 1;
return 0;
}
var obj = objArr.sort(compare);
response.send(obj);
but the response that came back is not ordered.
how can I fix it? thanks