const list = [
{type: '2', isEnable: false,},
{type: '3', isEnable: true,},
{type: '1', isEnable: true,},
{type: '4', isEnable: false,},
{type: '0', isEnable: true,}
]
根据type升序
list = list.sort((a, b) => a.type - b.type)
首先isEnable为true排前面,然后type升序
list = list.sort((a, b) => a.type - b.type)
list = list.sort((a, b) => a.isEnable> b.isEnable? -1 : 1)
list = list.sort((a, b) => {
if(a.isEnable == b.isEnable){
return a.type - b.type
}else{
return a.isEnable > b.isEnable? -1 : 1
}
})
list = list.sort((a, b) => a.isEnable == b.isEnable ? (a.type - b.type) : (a.isEnable > b.isEnable? -1 : 1))