Skip to content

Filter object keys and values into a new object

License

Notifications You must be signed in to change notification settings

johansteffner/filter-obj

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

filter-obj Build Status

Filter object keys and values into a new object

Install

$ npm install --save filter-obj

Usage

const filterObj = require('filter-obj');

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

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

const newObject2 = filterObj(obj, ['bar']);
//=> {bar: true}

API

filterObj(source, filter)

source

Type: object

Source object to filter properties from.

filter

Type: array function

Array of properties that should be filtered from the object or a filter function. The function has the signature filterFn(sourceKey, sourceValue, source).

Related

  • map-obj - Map object keys and values into a new object
  • object-assign - Copy enumerable own properties from one or more source objects to a target object

License

MIT © Sindre Sorhus

About

Filter object keys and values into a new object

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%