Skip to content

Instantly share code, notes, and snippets.

@ravenjohn
Created March 5, 2015 19:42
Show Gist options
  • Save ravenjohn/563a253b712f1f279167 to your computer and use it in GitHub Desktop.
Save ravenjohn/563a253b712f1f279167 to your computer and use it in GitHub Desktop.
Search `user` on `this`
var search = 'user',
on = this,
max_depth = 30,
found = [],
recurse = function (obj, from, depth) {
var i;
if (depth >= max_depth) {
return;
}
from = from || '';
for (i in obj) {
if (obj[i]
&& obj.hasOwnProperty
&& obj.hasOwnProperty(i)
&& obj[i] !== search
&& !obj[i].been_here
&& i !== 'been_here'
&& obj[i] !== found
// uncomment the following if you're looking inside the DOM, only the global vars
&& obj[i] !== document
&& !obj[i].tagName
&& !obj[i].nodeName
) {
if (typeof obj[i] !== 'object') {
if (~(i + '').indexOf(search) || ~(obj[i] + '').indexOf(search)) {
var temp = {};
temp[i] = obj[i];
temp.from = from + '[' + i + ']';
console.log(temp);
found.push(temp);
}
}
else if (typeof obj[i] === 'object' && !obj[i].been_here) {
obj[i].been_here = true;
recurse(obj[i], from + '[' + i + ']', depth++);
}
}
}
};
recurse(on, '', 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment