Website Toolbox Pro

Javascript: Using A String As A Variable

Javascript Comments »
I have a function that I send a javascript array to like so:

if (VAR_clicked == "one") {
    FUN_Table(VAR_array_one);
} else if (VAR_clicked == "two") {
    FUN_Table(VAR_array_two);
} else if (VAR_clicked =="etc") {
    FUN_Table(VAR_array_etc);
}

My problem now is I have many more arrays and want to do something like this:

FUN_Table("VAR_array_" + VAR_clicked);

I’m trying to use a string to pass a variable to the function, this does not work.
Any ideas as to how I can do this?

Continue reading Javascript: Using A String As A Variable »

How Can I Declare A Global Variable Inside A Javascript Function?

Javascript Comments »
Is it possible to declare a global variable inside a javascript function?
If you create any variable inside a function, its scope will be local to that function only and not global. Declare your variable outside the function.

Javascript: Variables Within Regex?

Javascript, Regular Expressions Comments »
Is it possible to use a variable within a regular expression declaration? For example:

var findThs="test123";
var mystring = "This is some test123 text";
var result = myString.match(/findthis(?:,| |$)/);

This doesnt return a result since findthis is being interpreted as text rather than a variable. I want its contents to be inserted into the regex expression.

Continue reading Javascript: Variables Within Regex? »