Skip to content

Instantly share code, notes, and snippets.

@hughdunne
Created September 16, 2016 19:21
Show Gist options
  • Save hughdunne/e55b600ee32ca3a3c2ed3d42f0291093 to your computer and use it in GitHub Desktop.
Save hughdunne/e55b600ee32ca3a3c2ed3d42f0291093 to your computer and use it in GitHub Desktop.
var path = [];
function searchObj(obj,str) {
try {
if (typeof obj === "string") {
if (obj.toLowerCase().indexOf(str.toLowerCase()) >= 0) {
console.log(path.join("/") + " : " + obj);
}
} else if (obj && typeof obj === "object" && obj.constructor.name === 'Object') {
// Note: we want to avoid HTMLElements, circular structures etc. hence check constructor name
for (var k in obj) {
path.push(k);
searchObj(obj[k], str);
path.pop();
}
}
} catch(err) {
console.log(err.message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment