var numbers = {
"value": [{
"num1": 1,
"num2": 10
},
{
"num1": 15,
"num2": 13
},
{
"num1": 26,
"num2": 24
},
{
"num1": 6,
"num2": 25
},
{
"num1": 15,
"num2": 20
}
]
};
var sortedNumbers = numbers.value.sort(function(x, y) {
return x['num2'] < y['num2'] ? 1 : -1;
});
console.log(sortedNumbers);
The result after the initial sorting should be further sorted as follows:
[
{
"num1": 6,
"num2": 25
},
{
"num1": 15,
"num2": 20
},
{
"num1": 1,
"num2": 10
}
{
"num1": 26,
"num2": 24
},
{
"num1": 15,
"num2": 13
}
]
Therefore, the sorting order should be based on the highest value of "num2" first and then in descending order as long as "num2" is greater than "num1". I have tried various methods without success; any assistance would be greatly appreciated.
Thank you for your help!