I have 2 sets in an array, each of these sets is an array of objects. I'd like to sort both of them using _.each and return a sorted object with the following:
var O1 = [{'name':'one'}, {'name':'two'}, {'name':'three'}, {'name':'four'}, {'name':'five'}, {'name':'six'}];
var O2 = [{'name':'rat'}, {'name':'cat'}, {'name':'lion'}, {'name':'tiger'}, {'name':'dog'}, {'name':'horse'}];
var sortIt = [O1, O2];
_.each(sortIt, function(item){
item = _.sortBy(item, function(arr){
return arr.name;
})
return item;
})
console.log(O1, "\n", O2); //nothing changed!
... but, apparently, nothing changes. The question is, what should be the proper approach?