You are looking for a for / in loop.
To get all global variables:
for(var name in this) { var value = this[name];
(This will only work correctly when launched in the global area, you can wrap it with an anonymous function to provide this. However, be careful with with blocks)
To get all the properties of a specific object:
for(var name in obj) { //Optionally: if (!obj.hasOwnProperty(name)) continue; //Skip inherited properties var value = obj[name]; //Do things }
However, there is no way to iterate over all local variables.
SLaks source share