Created
December 24, 2010 23:49
-
-
Save creationix/754572 to your computer and use it in GitHub Desktop.
Revisions
-
creationix created this gist
Dec 24, 2010 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ function find(root, obj) { var seen = []; function search(root, name, depth) { if (root === obj) { console.log(name); return; } if (!depth) { return; } if (seen.indexOf(root) >= 0) { return; } if (typeof root !== "object") { return; } seen.push(root); try { Object.getOwnPropertyNames(root).forEach(function (key) { search(root[key], name + "." + key, depth - 1); }); } catch (err) {} } search (root, "root", 5); }