npm.io
1.0.3 • Published 9 years ago

object-retain

Licence
MIT
Version
1.0.3
Deps
0
Vulns
0
Weekly
0

object-retain

Retains elements in object that matches filter

npm install --save object-retain

Examples

var retain = require('object-retain');

var obj =
{
	1: 'a',
	2: 'b',
	3: 'c',
	4: 'd'
}

retain(obj, (val, key) => key % 2 === 0);
// => returns obj
//a: { 2: 'b', 4: 'd' }

Object-Retain can be used to be called directly by Objects

Object.prototype.retain = require('object-retain');

var obj =
{
	1: 'a',
	2: 'b',
	3: 'c',
	4: 'd'
}

obj.retain((val, key) => key % 2 === 0);
// => returns obj
//a: { 2: 'b', 4: 'd' 

API

retain(object, filter)
arguments
  • object: (object)
  • filter: function(value, key, object)
returns
  • array
retain(filter) (if this is an object)
arguments
  • filter: function(value, key, object)
returns
  • this

Keywords