filter-obj

Filter object keys and values into a new object

Usage no npm install needed!

<script type="module">
  import filterObj from 'https://cdn.skypack.dev/filter-obj';
</script>

README

filter-obj

Filter object keys and values into a new object

Install

$ npm install filter-obj

Usage

import filterObject from 'filter-obj';

const object = {
    foo: true,
    bar: false
};

const newObject = filterObject(object, (key, value) => value === true);
//=> {foo: true}

const newObject2 = filterObject(object, ['bar']);
//=> {bar: false}

API

filterObject(source, filter)

filterObject(source, includeKeys)

source

Type: object

The source object to filter properties from.

filter

Type: (sourceKey, sourceValue, source) => boolean

A predicate function that detemines whether a property should be assigned to the new object.

includeKeys

Type: string[]

An array of property names that should be assigned to the new object.

Related

  • map-obj - Map object keys and values into a new object