javascript - Checking for multiple values in object -
this question has answer here:
what easiest way check undefined, null , "" in case:
i receiving object can have , of 3 states, , comes in form of:
images[0].url
images might not exists @ images might have url property of null images might have property of ""
i using if(images[0]), covers existence of [0], not deeper. how can solve this, without switch statement.
i tried this:
if((object.images[0]) || (object.images[0].url)){ } else { } but if [0] exists , url not, this. uncaught typeerror: cannot read property 'url' of undefined
you error when object. images[0] not exist. avoid have gradual check this.
if(object.images && object.images[0] && object.images[0].url){ //do stuff }
Comments
Post a Comment