JavaScript — Nested Objects

Generally, we get to deal with nested objects with higher depths as well. It becomes really challenging to check if they exist or undefined. At times such mistakes may break the UI as well. If we go for nested checks, the code looks clumsy. The following package comes in handy to solve this issue.

Npm Package: https://www.npmjs.com/package/is-obj-props

Details:

Package name: 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

How to Use

Install and import is-obj-props

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

This never lets us face undefined error due to object properties again.

Contribution

You are welcome to raise issues and PRs in the [repository](https://github.com/vilvaathibanpb/is-obj-props)

6+ years of Experience in React-Redux / NodeJS / GraphQL / TypeScript. https://vilvaathiban.com

6+ years of Experience in React-Redux / NodeJS / GraphQL / TypeScript. https://vilvaathiban.com