Skip to content

Instantly share code, notes, and snippets.

@bcherry
Created July 6, 2011 21:47
Show Gist options
  • Save bcherry/1068427 to your computer and use it in GitHub Desktop.
Save bcherry/1068427 to your computer and use it in GitHub Desktop.
search javascript objects by name
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