var data = {
"input": [{
"countA": 1,
"countB": 10
},
{
"countA": 15,
"countB": 13
},
{
"countA": 26,
"countB": 24
},
{
"countA": 6,
"countB": 25
},
{
"countA": 15,
"countB": 20
}
]
};
var sorted = data.input.sort(function(a, b) {
return a['countB'] < b['countB'] ? 1 : -1;
});
console.log(sorted);
The outcome after the first sorting should be after another sorting:
[
{
"countA": 6,
"countB": 25
},
{
"countA": 15,
"countB": 20
},
{
"countA": 1,
"countB": 10
}
{
"countA": 26,
"countB": 24
},
{
"countA": 15,
"countB": 13
}
]
So, it should be the highest of "countB" and then descending as long as "countB" is higher than "countA". So far I tried multiple ways, but there's no outcome so far.
Thanks for any help!