documentcloud/underscore — Issue #373: extend _.compact(array) to support Objects
Author: yelled3
Created: 2011-11-17 13:32:29+00:00
State: open

it would be great if _.compact would be something like:

```javascript

// Trim out all falsy values from an array.
_.compact = function(item) {
if _.isArray(item){
return _.filter(array, function(value){ return !!value; });
}
else return _.compactObject(item);
};

/**
* Trim out all falsy values from an object.
*
* @param obj - object
*/
compactObject : function compactObject(obj) {
_.each(obj, function(value, key) {
if(!value){
delete obj[key];
}
});
return obj;
}
```