Skip to content

Instantly share code, notes, and snippets.

@jpillora
Created April 22, 2013 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpillora/5432749 to your computer and use it in GitHub Desktop.
Save jpillora/5432749 to your computer and use it in GitHub Desktop.
Recursive enumeration of object contents
var visited = [], type, str;
var visit = function(val, path) {
if(!path) path = '';
if(visited.indexOf(val) >= 0) return;
visited.push(val);
type = typeof val;
str = type !== 'function' ? val : '*';
console.log(path, ' - ', type, str);
if(!val || val.jquery || val instanceof HTMLElement ||
(typeof val !== 'object' && typeof val !== 'function')) return
for(var key in val)
visit(val[key], path+($.isArray(val) ? '[' + key + ']' : '.' + key));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment