There are many questions regarding sorting with JavaScript but I didn\'t find anything that addresses this case so I don\'t believe this is a duplicate.
I\'m getting dat
Here's my solution. If you know that both arrays will match in length and location of id's, then this is a concise solution:
_.chain(items)
.merge(order)
.sortBy('sortindex')
.map(_.partialRight(_.omit, 'sortindex'))
.value()
Otherwise, if they aren't guaranteed to be sorted, then the items can be resolved with a map/find/merge.
_.chain(items)
.map(function(item) {
return _.merge(item, _.find(order, {'id': item.id}));
})
.sortBy('sortindex')
.map(_.partialRight(_.omit, 'sortindex'))
.value()