time-to-botec/squiggle/node_modules/@stdlib/utils/pick-by
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00
..
docs feat: add the node modules 2022-12-03 12:44:49 +00:00
lib feat: add the node modules 2022-12-03 12:44:49 +00:00
package.json feat: add the node modules 2022-12-03 12:44:49 +00:00
README.md feat: add the node modules 2022-12-03 12:44:49 +00:00

pickBy

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

Usage

var pickBy = require( '@stdlib/utils/pick-by' );

pickBy( obj, predicate )

Returns a partial object copy containing 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 = pickBy( obj1, predicate );
// returns { 'b': 2, 'c': 3 }

Notes

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

Examples

var pickBy = require( '@stdlib/utils/pick-by' );

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

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

var obj2 = pickBy( obj1, predicate );
// returns { 'b': 2, 'c': NaN }