A CRUD API to manipulate objects in depth. Get, Set, Update and Delete functions available.
With npm
npm install deep-objectvar deepObj = require('deep-object');
var obj = {
level1:{
level2:{
level3:{
name: "Foo"
}
},
anotherLevel2: "bar"
}
};
deepObj.get(obj, ["level1", "level2"]); //returns {level3: {name: "Foo"}}
deepObj.set(obj, ["level1", "level2"], "FooBar"); //Sets level2 to "FooBar"
deepObj.remove(obj, ["level1", "level2"]); //Object now becomes, {level1: {}}Gets the value at the given path
objectis a JS objectpathis a string array containing keys from outermost to innermost.
Sets/updates given value at the path.
objectis a JS objectpathis a string array containing keys from outermost to innermost.valueis any valid JS variable.
Removes the given path element.
objectis a JS objectpathis a string array containing keys from outermost to innermost.
I needed this for a project. Didn't look through NPM for this. Here is my implementation.