Home >Web Front-end >JS Tutorial >arguments object_basic knowledge
In JavaScript, you can access parameter names without explicitly naming them. For example:
function hi(){
if(arguments[0]=="andy"){
return;
}
alert(arguments[0]);
}
Use arguments[0] to access the first parameter, and so on.
Overloading can be achieved by using the arguments object, and the number of parameters of the function can be obtained by using arguments.length, as follows:
function hi(){
if(arguments.length==1){
alert (arguments[0]);
}
else if(arguments.length==2){
alert(arguments[0] argument[1]);
}
}
<script> <BR>function fun() <BR>{ <BR>var arr=fun.arguments; <BR>for(var i=0;i<arr.length;i++) <BR>{ <BR>alert(arr[i]); <BR>} <BR>} <BR>fun("aa","bb","cc"); <BR></script>