Created
July 6, 2011 21:47
-
-
Save bcherry/1068427 to your computer and use it in GitHub Desktop.
search javascript objects by name
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 grep = function(o, n) { | |
var s = ""; | |
if (typeof o === "string") { | |
n = o; | |
o = window; | |
s = "window" | |
} | |
function actualGrep(o, n, s) { | |
Object.keys(o).forEach(function(k) { | |
var v = o[k]; | |
if (k == n) { | |
console.log("%s.%s -> (%o) %o", s, k, typeof v, v); | |
} | |
if (("" + v) == "[object Object]" && k != "window" && s.split(".").indexOf(k) == -1) { | |
actualGrep(v, n, (s ? s + "." : "") + k) | |
} | |
}); | |
} | |
actualGrep(o, n, s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment