I receive an object from an API call. I want to check:
- If the object exists
- Whether the object's property has the property I'm looking for or not
Let's say that I'm expecting the following object of objects:
success.response.data.users.items.list
Now I want to know if this list object exists or not.
I have tried:
typeof success.response.data.users.items.list !== "undefined"Error I got:
TypeError: Cannot read property 'data' of undefinedsuccess.hasOwnProperty("response.data.users.items.list")This always evaluates to false because
hasOwnPropertycannot check multi-level objects apparently.success.response.data.users.items.hasOwnProperty("list")Error I got:
TypeError: Cannot read property 'data' of undefined
Is there any modern and quick way of checking this?