0

my previous question about this dealt with global vars
but unfortunatley the window of opportunitys doesn't work with this next example because it alerts 4 times instead of only 1

test("a","b","c");
function test(var0,var1,var2,var3) {
    for(var i=0; i<4; i++) {
        if(window["var"+i]===undefined) {alert("test");}
    }
}

this may not be very clear so I will try again
this time I want it to alert all three vars

test("a","b","c");
function test(var0,var1,var2) {
    for(var i=0; i<3; i++) {
        alert(window["var"+i]);
    }
}

how can I achieve the identical results as with the window["str"+var] from within a function?

2
Contributors
1
Reply
8
Views
3 Years
Discussion Span
Last Post by felgall
1

All of the values passed to a function are stored in "arguments".

test("a","b","c");
function test(var0,var1,var2) {
    for(var i=0; i<3; i++) {
        alert(arguments[i]);
    }
}

Edited by felgall

Votes + Comments
thanks :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.