omitBy

Return a partial object copy excluding properties for which a predicate (function) returns a truthy value.

Usage

var omitBy = require( '@stdlib/utils/omit-by' );

omitBy( obj, predicate )

Returns a partial object copy excluding properties for which a predicate returns a truthy value.

function predicate( key, value ) {
    return ( value > 1 );
}

var obj1 = {
    'a': 1,
    'b': 2,
    'c': 3
};

var obj2 = omitBy( obj1, predicate );
// returns { 'a': 1 }

Notes

  • The function returns a shallow copy.
  • The function only copies own properties. Hence, the function never copies inherited properties.

Examples

var omitBy = require( '@stdlib/utils/omit-by' );

function predicate( key, value ) {
    return ( typeof value === 'number' );
}

var obj1 = {
    'a': '1',
    'b': 2,
    'c': NaN,
    'd': null
};

var obj2 = omitBy( obj1, predicate );
// returns { 'a': '1', 'd': null }
Did you find this page helpful?