Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
116
rated 0 times [  121] [ 5]  / answers: 1 / hits: 19819  / 9 Years ago, wed, february 25, 2015, 12:00:00

I have an array with keys like so:



['asdf12','39342aa','12399','129asg',...] 


and a collection which has these keys in each object like so:



[{guid: '39342aa', name: 'John'},{guid: '129asg', name: 'Mary'}, ... ]


Is there a fast way to sort the collection based on the order of keys in the first array?


More From » arrays

 Answers
25
var sortedCollection = _.sortBy(collection, function(item){
return firstArray.indexOf(item.guid)
});

[#67672] Tuesday, February 24, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;