I have a list of javascript variable like this
var_111, var_222, var_132, var_122bb …
The string after the underscore are response from a remote server, so I cannot specify them beforehand.
I want to run a for loop that would iterate through all the var_* variables. For example console.log all the variables.
I guess it can be done with regex but I really haven’t learn it yet. Hope someone can help!
Based on the clarification below, assuming what is actually going on is that the server is setting a bunch of global variables whose names you can’t control, what you want is:
This iterates over all global variables and compares them to the regular expression to get the ones of the type var_###, and prints them out for you. You can get the values with
window[k]. This works because all global variables are in fact properties of thewindowobject.