Javascript 当属性与使用lodash的特定值匹配时,从集合中删除项

Javascript 当属性与使用lodash的特定值匹配时,从集合中删除项,javascript,lodash,Javascript,Lodash,我有一个收藏 var users = [ {'user': 'Mike', 'age': 11, 'description': 'Null'}, {'user': 'Kiddo', 'age': 36, 'description': 'Not Available'}, { 'user': 'Jack', 'age': 36, 'description': 'test'} ]; 如何使用lodash库删除具有“说明”:“不可用”的条目

我有一个收藏

 var users = [
       {'user': 'Mike', 'age': 11,  'description': 'Null'},
       {'user': 'Kiddo', 'age': 36,  'description': 'Not Available'},
       { 'user': 'Jack', 'age': 36,  'description': 'test'}
     ];
如何使用lodash库删除具有“说明”:“不可用”的条目

编辑1: 尝试使用下面的

function removeItemsByAttrValue (collection, attrValue, matchValue) { 
    return _.filter(collection, val => val.attrValue !== matchValue);
}
就是说,

 removeItemsByAttrValue (users, 'description', 'Not Available');

不知何故,这并没有过滤该项。

您可以对数组使用内置的JS方法
filter

var filteredUsers = users.filter(val => val.description !== 'Not Available');
Lodash也有一个过滤方法,但这里不需要使用

_.filter(users, val => val.description !== 'Not Available') 

您可以对数组
filter

var filteredUsers = users.filter(val => val.description !== 'Not Available');
Lodash也有一个过滤方法,但这里不需要使用

_.filter(users, val => val.description !== 'Not Available') 

过滤,拒绝或删除。可能重复过滤,拒绝或删除。可能重复感谢,当我在函数中使用它并传递参数时,不知何故它不会过滤。我用我试过的方法编辑了这个问题。但如果过滤器按原样使用,则需要更新函数,使其如下所示:
.filter(collection,val=>val[attrValue]!==matchValue).filter(collection,val=>val[attrValue]!==matchValue)