📌  相关文章
📜  loadash 按另一个数组的顺序排序 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:56.237000             🧑  作者: Mango

代码示例1
var firstArray = ['asdf12','39342aa','12399','129asg',...];

// a collection which has these keys in each object like so:
var collection = [{guid: '39342aa', name: 'John'},{guid: '129asg', name: 'Mary'}, ... ];

const last = collection.length;

var sortedCollection = _.sortBy(collection, function(item){
  return firstArray.indexOf(item.guid) !== -1
      ? firstArray.indexOf(item.guid) : last;
});