I have this array:
var array = [{
"datecrea":"2020-01-31T16:14:46+01:00",
"datas":{
"badge":"new",
"downloads":1,
},
},
{
"datecrea":"2020-01-31T17:14:46+01:00",
"datas":{
"badge":"soon",
"downloads":0,
},
},
{
"datecrea":"2020-01-31T18:14:46+01:00",
"datas":{
"badge":"",
"downloads":3,
},
},
{
"datecrea":"2020-01-31T19:14:46+01:00",
"datas":{
"badge":"topten",
"downloads":5,
},
},
{
"datecrea":"2020-01-31T20:14:46+01:00",
"datas":{
"badge":"new",
"downloads":1,
},
}]
I want to sort this array but using multiple values and here's the sorting steps:
- badge
- "soon" is the most important
- "new"
- "topten" is the least important one
- downloads
- datecrea
I already have this code which sorts by date and then by downloads:
array.sort(function(a,b){
return new Date(b.datecrea) - new Date(a.datecrea);
})
.sort(function(a,b){
return b.datas.downloads - a.datas.downloads;
})