Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

loadash sort by order of another array

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;
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #loadash #sort #order #array
ADD COMMENT
Topic
Name
2+5 =