1.0.3 • Published 7 years ago
object-retain v1.0.3
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