I have an array of objects that look like this:
[
{
name: s1,
isDefault: false
},
{
name: s2,
isDefault: true
},
{
name: s3,
isDefault: false
}
]
I want to sort this array so that the element with isDefault: true
is placed first, and have the rest follow this object in alphabetical order.
In other words:
[
{
name: s2,
isDefault: true
},
{
name: s1,
isDefault: false
},
{
name: s3,
isDefault: false
}
]
I know how to accomplish the first condition:
objPanoramas.sort((a, b) => {
return a.isDefault < b.isDefault
})
How can I integrate the second condition?