Search code examples
javascriptlodash

How do I omit a key pair from an object based on its value?


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


Solution

  • You can use _.omit with a callback:

    _.omit(filters, function (value) {
        return value === 'width';
    })