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
}
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
}
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
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]);
}
}
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]);
}