ECMAScript 5.1 provided us with a wonderful
Array.prototype.filter method to filter arrays and return only lists of values filtered by our condition. But for the same operation on objects, we always have to go for less functional approaches.
One option is to filter our object properties. If it’s a recurrent operation, we could polyfill a method for the
Object prototype, which does it for us:
Now you can easily filter the object properties passing a predicate callback, which return “true” or “false,” to filter the object properties.
This implementation iterates only over the
enumerableproperties of the object.