dublintech
dublintech

Reputation: 17785

Dynamic Arguments in Javascript

In Javascript, you are supposed to be able to access the arguments passed to a function via the arguments key word. This should alert "tony" and "magoo" but instead it alerts "undefined" - why?

function myFunction(){
    for(var i=0; i<arguments.length; i++){
        alert(arguments[i].value);
    }
}

myFunction("tony", "Magoo");

Upvotes: 0

Views: 406

Answers (1)

Rob W
Rob W

Reputation: 348962

Use arguments[i], without .value.

The arguments object is an array-like object, all arguments can be accessed through numeric indices.

Upvotes: 6

Related Questions