Can someone help me with Array.sort()?
I can do sorting on one value (e.g. return a < b
) but not with more values.
I need this case, when some primary values has the same result.
E.g. array:
var data = [
{
"name": "Paolos Pizza",
"rating_count": 20,
"rating_value": 5,
"price": 7
},
{
"name": "Bella Italia",
"rating_count": 55,
"rating_value": 3,
"price": 7
},
{
"name": "Mama Mia",
"rating_count": 2,
"rating_value": 5,
"price": 99
},
{
"name": "Mario's" ,
"rating_count": 23,
"rating_value": 6,
"price": 7
},
{
"name": "Colazione e Roma" ,
"rating_count": 52,
"rating_value": 4,
"price": 7
}
];
First I want to sort the Array descending on the key price
. If some entries have the same price, than I want to sort it ascending depending on rating_value
. If some entries have the same price
and the same rating_value
, than I want to sort ascending on rating_count
.
How can I solve this?