keyfinder
v1.0.0
Published
Deep search for keys in objects and arrays and pluck their respective values.
Downloads
3,218
Maintainers
Readme
keyfinder
Deep search for keys in objects and arrays and pluck their respective values.
Install
$ npm install keyfinder --save
$ bower install keyfinder --save
Usage
keyfinder(object/array, "string")
Returns an array containing all the values of the keys that match the predicate.
var obj = {
a: 'aa',
b: 'bb',
c: 'cc'
d: {
a: 'aaa'
}
}
keyfinder(obj, 'a');
// → [ 'aa', 'aaa' ]
keyfinder(object/array, callback)
Iterates through the given object/array and calls the callback for every key/value pair.
// "obj" should be a JavaScript object or array.
keyfinder(obj, function(key, value, parent) {
// key = key or index depending on if the parent is an object or an array
// value = value of the key
// parent = type of parent, "object" or "array"
});
Tests
# clone this repo
$ npm install
$ npm test
License
MIT © Simon Johansson