0

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");
1
  • 1
    Note it's not a keyword, strictly speaking. It's basically just a variable. Commented Mar 17, 2012 at 16:55

1 Answer 1

6

Use arguments[i], without .value.

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

Sign up to request clarification or add additional context in comments.

2 Comments

Great answer. Is there a special name for this characteristic of the language
@dublintech There's no special name. It's just a variable, defined on every function instance. If you're looking for even more details: This is the specification for the arguments.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.