Reputation: 4132
I am using lodash.js and am trying to remove a key pair from the below object based on the value not the key name - note, I cannot use the key name:
var filters = {
"filter1": "height",
"filter2": "length",
"filter3": "width"
}
This will remove a key pair by name
_.omit(filters, 'filter1');
Does anyone know how to removed it based upon value? Cheers
Upvotes: 2
Views: 802
Reputation: 4259
API : omitBy(object, predicate)
[predicate=_.identity] (Function): The function invoked per property.
use omitBy
that accepts a function callback on each value to be processed.
_.omitBy(filters, function (value) {
return value === 'width';
})
Upvotes: 0
Reputation: 187034
According to the docs omit
it can take a call back argument that is a function that returns true for each pair that should be omitted. In that function you can do whatever crazy logic you like.
_.omit(filters, function(value, key, object) {
return value === 'width'; // omit width
});
Upvotes: 2