Created
September 16, 2016 19:21
-
-
Save hughdunne/e55b600ee32ca3a3c2ed3d42f0291093 to your computer and use it in GitHub Desktop.
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
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