how to sort an array of objects using a related property from objects in second array
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 data like this back from an api: //items array var items = [{id:1, name:'bill'}, {id:2, name:'sam'}, {id:3, name: mary}, {id:4, name:'jane'}] //sort order array var order = [{id:1, sortindex:4}, {id:2, sortindex:2}, {id:3, sortindex: 1}, {id:4, sortindex:3}] How can I sort the items array by the sortindex property of the objects in the order array? The objects in the two arrays have the common property id . Is there an elegant lodash