The hasIn
function from Lodash allows you to check if a given property key exists in a nested object by passing in the object and the property path as arguments. Here's an example of how to use it:
index.tsx326 chars16 lines
In this example, we require the lodash
library and create an object called myObject
with some nested properties. We then use the hasIn
function to check if the name
property exists (which it does), if the address.city
property exists (which it does), and if the address.zipCode
property exists (which it does not).
By using the hasIn
function, we can avoid getting errors when trying to access properties that don't exist within a nested object.
gistlibby LogSnag