135
rated 0 times
[
139]
[
4]
/ answers: 1 / hits: 15355
/ 8 Years ago, mon, december 12, 2016, 12:00:00
I'm trying to sort this array of objects by its boolean properties however, I'm struggling to find a solution with javascripts 'sort' method
I'm trying to sort it, so the top item in the array would be 'offer = true', then 'shortlisted = true', and finally 'rejected = true'.
var toSort = [{
offer: false,
shortlisted: true,
rejected: false,
stage: 2
}, {
offer: false,
shortlisted: false,
rejected: true,
stage: null
}, {
offer: true,
shortlisted: true,
rejected: false,
stage: null
}, {
offer: false,
shortlisted: true,
rejected: false,
stage: 1
}];
This is the final result I would like to achieve
[{
offer: true,
shortlisted: true,
rejected: false,
stage: null
}, {
offer: false,
shortlisted: true,
rejected: false,
stage: 1
}, {
offer: false,
shortlisted: true,
rejected: false,
stage: 2
}, {
offer: false,
shortlisted: false,
rejected: true,
stage: null
}]
What is the best method to sort this array?
More From » arrays