Last active
April 3, 2016 23:54
-
-
Save Artistan/1d2d62f46b64724d088a0d47035076dc to your computer and use it in GitHub Desktop.
Find properties within a javascript object/array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recursiveIterationKey(object,matchKey) { | |
var found=false; | |
for (var property in object) { | |
if (object.hasOwnProperty(property)) { | |
if (typeof object[property] == "object"){ | |
if(recursiveIterationKey(object[property])){ | |
found=true; | |
break; | |
} else if(matchKey==property) { | |
found = true; | |
} | |
}else{ | |
//found a property which is not an object, check for your conditions here | |
if(matchKey==property){ | |
found = true; | |
} | |
} | |
} | |
} | |
return found; | |
} | |
function recursiveIterationValue(object,matchValue) { | |
var found=false; | |
for (var property in object) { | |
if (object.hasOwnProperty(property)) { | |
if (typeof object[property] == "object"){ | |
if(recursiveIterationValue(object[property])){ | |
found=true; | |
break; | |
} | |
}else{ | |
//found a property which is not an object, check for your conditions here | |
if(matchValue==object[property]){ | |
found = true; | |
} | |
} | |
} | |
} | |
return found; | |
} | |
function recursiveIterationKeyValue(object,matchKey,matchValue) { | |
var found=false; | |
for (var property in object) { | |
if (object.hasOwnProperty(property)) { | |
if (typeof object[property] == "object"){ | |
if(recursiveIterationKeyValue(object[property])){ | |
found=true; | |
break; | |
} else if(matchKey==property && matchValue==object[property]) { | |
found = true; | |
} | |
}else{ | |
//found a property which is not an object, check for your conditions here | |
if(matchKey==property && matchValue==object[property]){ | |
found = true; | |
} | |
} | |
} | |
} | |
return found; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment