JavaScript get nested property without breaking

Viewed 217

I am receiving a deeply nested object. I don't know which properties will be present. If I want to get the image, I can't just do this

data.opposite.info.logo.images.s.resized_urls.s,

Imagine this comes from a system where user can leave the logo empty, then my code will break. Do I need to check the existence of properties like this?

if(data.opposite){

   if(data.opposite.info)

     if(data.opposite.info.images)

//...etc
}
2 Answers
Related