I have 2 lists of objects:
people =
[{id: 1, name: "Tom", carid: 1},
{id: 2, name: "Bob", carid: 1},
{id: 3, name: "Sir Benjamin Rogan-Josh IV", carid: 2}];
cars=
[{id: 1, name: "Ford Fiesta", color: "blue"},
{id: 2, name: "Ferrari", color: "red"},
{id: 3, name: "Rover 25", color: "Sunset Melting Yellow with hints of yellow"}];
Is there a function (possibly in Angular, JQuery, Underscore, LoDash, or other external library) to do a left join in one line on these? Something like:
peoplewithcars = leftjoin( people, cars, "carid", "id");
I can write my own, but if LoDash has an optimised version I'd like to use that.
Linq.js http://linqjs.codeplex.com/ will do joins along with many other things
It is not hard to implement using underscore.js
No, LoDash does not have join it's prety easy to implement your own though, this isn't quite a join but selects all people with a matching car:
Have a look at this: Six join implementations in javascript.
This example uses Lodash to left join the first matched object. Not quite what the question asks, but I found a similar answer helpful.
Results
Here's a simple loop I did for a Javascript (JQuery in this case) to "join" obj1 and obj2 on someID and add one property from obj2 to obj1.
If you want to do a more complete join, you can go through and expand it to loop on obj2.hasOwnProperty() and copy that over as well.