Library to add, delete and retrieve keys from objects.
npm install keyleet
This module exports one object containing three functions: deleteKeys, addKeys and accessValueByString, example of using this library is shown below.
AddKeys & DeleteKeys
The documentation for the deleteKeys & addKeys method is basically the same, the examples apply to both functions but deleteKeys is used as an example.
var keyleet = ;var object =data:name: 'Testy Test'firstName: 'Testy'lastName: 'Test';var modifiedObject = keyleet; // Returns object not containing name attribute in the data array anymore.
Things to note
First parameter passed to the function should always be an object literal for now.
The second object describes which keys you would like removed from the object. These can be four of the following options:
String in the form of:
key.nestedkey. Example for the above object would be:
Object containing the keys, example for the above object would be:
var removeKeysObject =data:name: ''
The values of these keys don't matter, can be either null or some value.
Array containing strings described in number 1. Example would be:
Array containing objects described in number 2. Example for above object would be:
var arrayOfRemoveKeysObjects =data:name: ''data:firstName: ''
- Array containing both strings and object described in number 1 & 2. Example for above object would be:
var mixedArrayOfRemoveKeys ='data.name'data:firstName: '''data.lastName';
If you have an object with several nested keys it can be hard to directly access the values of those nested keys.
This function makes it easy to do so and works as following:
var keyleet = ;var object =data:personalInfo:name:firstName: 'Testy';// Access nested propertyvar value = keyleet;// Access top level keyvar dataArray = keyleet;// Accessing nested property which doesn't resolve to a single valuevar personalInfoArray = keyleet;