is-obj-props
A small, yet very useful npm package, which is used to check if an object possess a property or not. Checks for any depth of nested objects
- If the object has the property, it will return the value
- If the property is not present, it returns 'null'
Installation
$ npm i is-obj-props
How to Use
Install and import is-obj-props
import isObjProps from 'is-obj-props'; const testObj =
isObjProps is a function which takes 2 arguements:
- Arguement 1 - Type: Object - The Object to be tested (testObj in this case)
- Arguement 2 - Type: Array - Array of Property names. The length of the array denotes the depth of the property in nested object.
The examples will make you understand better
console.log;//UserName console.log;//null console.log;//98 console.log;//{part1: 47, part2: 48} console.log;//null console.log;//48 console.log;//null
Benefits
This never lets us face undefined error due to object properties again.
Contribution
You are welcome to raise issues and PRs in the repository