Q:

Call a function with variable number of parameters

Possible Duplicate:
Pass arbitrary number of parameters into Javascript function 

How can the following be achieved with n arguments?
function aFunction() {

    if ( arguments.length == 1 ) {
        anotherFunction( arguments[0] );
    } else if ( arguments.length == 2 ) {
        anotherFunction( arguments[0], arguments[1] );
    } else if ( arguments.length == 3 ) {
        anotherFunction( arguments[0], arguments[1], arguments[2] );
    }

}

function anotherFunction() {
    // got the correct number of arguments
}

A:

You don't need to do this. Here is how you can call it without caring how many arguments you have:
function aFunction() {
    anotherFunction.apply(this, arguments);
}

function anotherFunction() {
    // got the correct number of arguments
}

