1 ) a way to iterate through the array objects that exist on a page without knowing their variable names.
Only if you know where they're stored. If they're all globals, for example, they are properties of the global object, meaning you can do:
Code:
var arrs = [];
for(var i in window)
if(window[i].constructor === Array)
arrs.push(window[i]);
2 ) to select one or more of them on the basis of their variable name matching a string.
Likewise:
Code:
var arrs = [];
for(var i in window)
if(window[i].constructor === Array && i.indexOf("myArrVars") !== -1)
arrs.push(window[i]);
Of course, in a well-designed script, this should never be necessary.
Alternatively, you could overwrite Array:
Code:
var tArr = function() {
return (Array.instances[Array.instances.length] = new RealArray);
};
tArr.instances = [];
RealArray = Array;
Array = tArr;
This will give you a nice neat array of all instances of Array in Array.instances, but may break some functionality (the Array(x, y, z) array constructor syntax for a start; there's probably a way around this, but I'm not yet sure what it is).
Bookmarks