1.0.5 • Published 7 years ago
looping-tool v1.0.5
Looping Tool 🚀
This method allows you to get an specific value from an nested object by passing a key as a string.
Installation 🔧
npm install looping-toolBenefits? 📌
Accessing a specific value from a nested object can be very annoying and you should always test if all the properties you are using exist.
if (OBJECT && OBJECT.whereIsTheKey && OBJECT.whereIsTheKey.here) {
let value = OBJECT.whereIsTheKey.here.oneOfThis
}This is necessary to avoid errors like "cannot read property 'here' of undefined". Forget about all that by using this method.
Using the method ⚙️
const loopingTool = require('looping-tool');
let OBJECT = {
second: {
test: 'hi',
test2: 'bie'
},
array: ['wii', 'debug', 'hahaha'],
whereIsTheKey: {
maybe: 'No',
here: {
oneOfThis: ['nop', 'almost', 'here']
}
}
};
let findedValue = loopingTool(OBJECT, 'oneOfThis');
console.log("Get Value By Key", findedValue);result:
Get Value By Key (3) ["nop", "almost", "here"]License
This package is licensed under the MIT License. Created by @facundo.marcet.