Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript loop all depths recursive object

var findObjectByLabel = function(obj, label) {
    if(obj.label === label) { return obj; }
    for(var i in obj) {
        if(obj.hasOwnProperty(i)){
            var foundLabel = findObjectByLabel(obj[i], label);
            if(foundLabel) { return foundLabel; }
        }
    }
    return null;
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #loop #depths #recursive #object
ADD COMMENT
Topic
Name
7+3 =