📅  最后修改于: 2022-03-11 14:48:33.608000             🧑  作者: Mango
var sortOrder = ['n', 'a', 'u'];
var myArray = [{
name: 'u'
},
{
name: 'n'
},
{
name: 'a'
},
{
name: 'n'
}
];
myArray.sort(function(a, b) {
return sortOrder.indexOf(a.name) - sortOrder.indexOf(b.name);
});
console.log(myArray);Save to mem.dev