You can iterate over all elements of the global scope, for example:
var test = 123, someVar = 812; for(key in window){ if(typeof window[key] === 'number' && window[key] == 123){ console.log(key, window[key]); } }
Combine this with some recursion, and you could theoretically iterate over all the objects and their child objects available in the object:
function searchObject(object, search){ for(key in object){ if(typeof object[key] === 'number' || typeof object[key] === 'string'){ if(object[key] === search){ console.log(key, window[key]); } }else if(typeof object[key] === 'object'){ searchObject(object[key], search); } } }
This is just a quick and dirty example. It only checks strict equality (so the "string does not contain"), and it iterates through the arrays using for in , which is evil. But this should give you an idea of ββhow this works.
Do not skip window or document to this function. This will not work due to circular links.
However, you can also place a breakpoint in your code in chrome dev tools .
Then you can check the current value of your variables in the "Area Scope" area on the right.
source share