I am writing a plugin for a website for which I have no control, besides my ability to add JS code to it (in fact, this is a set of html documents created by the outdated wysiwyg html editor).
For my purposes, I need to get all the variables that are named in a certain way. A name always starts with zzzand ends with a number, from zzz1to zzz999999. Now I am doing the following:
for (var i=1; i<999999; i++) {
if (typeof window['zzz'+i] !== 'undefined') {
ArrayOfAllFoundVariables.push( window['zzz'+i] )
}
}
I wonder if there is a more efficient way to detect these variables besides iterating through a million uncertain ones.
source
share