3

I have jQuery function like this and i need to find no of parameters passed in this jQuery function.

function Customer(Name, Age, Location) {
    // Find no. of parameter passed in this function
    // Eg: Here parameter count = 3
}
4

4 回答 4

2

You can use the arguments object

ex

var len = arguments.length
alert(len)

Demo: Fiddle

Then you can access the values using the index like arguments[0] will give the first parameter

于 2013-06-13T05:22:24.613 回答
1

You can use arguments.length to find total no of arguments

And to find the arguments iterate by using following loop.

 function function_name() {
      for (var i = 0; i < arguments.length; i++) {
        alert(arguments[i]);
      }
    }
于 2013-06-13T05:24:41.727 回答
1

arguments.length will print the number of arguments passed to a function. This will work no matter what the function statement looks like (for example - could be function(){}, or even function Customer(Name, Age, Location){}.

Try printing to the console:

console.log(arguments.length);

or showing an alert:

alert("Number of arguments: " + arguments.length);

To print the arguments, try this:

for (var i = 0; i < arguments.length; i++)
{
    console.log(arguments[i]);
}
于 2013-06-13T05:29:06.210 回答
0

you can use arguments object's length method,

eg.

alert(arguments.length)
于 2013-06-13T05:25:59.477 回答