1.0.5 • Published 5 years ago

looping-tool v1.0.5

Weekly downloads
6
License
MIT
Repository
-
Last release
5 years ago

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-tool

Benefits? 📌

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.

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago