[SCRIPT]-VERIFYING IF A DEEP PROPERTY EXISTS IN AN OBJECT

VERIFYING IF A DEEP PROPERTY EXISTS IN AN OBJECT

use a resolver:

function resolve(start) {
    return [].slice.call(arguments, 1).reduce(function(obj, prop) {
        return obj && obj[prop];
    }, start);
}


resolve(response, "objects", 0, "images", 0, "url");
if it returns undefined, then something along the way went bad...
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments