我有以下數組的對象,我需要通過_id
使用_id
值的數組進行過濾。LoDash的挑戰,我有一個對象的數組,我需要過濾,爲一個值的數組
var objects = [{
_account: "YzzrzBrO9OSzo6BXwAvVuL5dmMKMqkhOoEqeo",
_id: "055z5gzVyVfzlBnEOqYvcoLL1ZgOWJhkrWMkv2"
}, {
_account: "YzzrzBrO9OSzo6BXwAvVuL5dmMKMqkhOoEqeo",
_id: "LvvrvyrOGOS2e5yE0Bdki45Y1ndVlgfoZ2zoOp"
}, {
_account: "mjj9jp92z2fD1mLlpQYZI1gAd4q4LwTKmBNLz",
_id: "rEEwENwnznCQvkm61wRziKlMRPqaYztnR4vn61"
}, {
_account: "AaaraZrLqLfzRYoAPlb6ujPELWVW4dTK4eJWj",
_id: "944r40rPgPU2nXqzMYolS5nyo6Eo9OuqrlDkB"
}, {
_account: "AaaraZrLqLfzRYoAPlb6ujPELWVW4dTK4eJWj",
_id: "rEEwENwnznCQvkm61wZ9uey62Pjy5YTqgYGDK"
}];
var id_values = [
"rEEwENwnznCQvkm61wZ9uey62Pjy5YTqgYGDK",
"944r40rPgPU2nXqzMYolS5nyo6Eo9OuqrlDkB",
"rEEwENwnznCQvkm61wRziKlMRPqaYztnR4vn61"
];
我相信difference
,pull
或without
可能是有用的,但我不能從LoDash文檔告訴他們分開。我也認爲forEach
,forIn
或uniq
可能是有用的。我能過濾的對象之一了使用reject
:
_.reject(objects, {
_id: "rEEwENwnznCQvkm61wZ9uey62Pjy5YTqgYGDK"
});
不過這並不能幫助我需要通過一個數組來過濾。結果應該是以下數組:
var result = [{
_account: "YzzrzBrO9OSzo6BXwAvVuL5dmMKMqkhOoEqeo",
_id: "055z5gzVyVfzlBnEOqYvcoLL1ZgOWJhkrWMkv2"
}, {
_account: "YzzrzBrO9OSzo6BXwAvVuL5dmMKMqkhOoEqeo",
_id: "LvvrvyrOGOS2e5yE0Bdki45Y1ndVlgfoZ2zoOp"
}];
感謝您的幫助。 – rashadb 2015-02-06 04:11:32