Joins in Javascript

后端 未结 8 2267
醉话见心
醉话见心 2020-12-14 03:31

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\", car         


        
8条回答
  •  执笔经年
    2020-12-14 04:19

    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:

        var peopleWithCars = _.filter(people, function (person) {
            return _.exists(cars, function(car) {
                return car.id === person.id;
            });
        });
    

提交回复
热议问题