javascript中arguments的理解使用

javascript中arguments可以理解为一个属性,也是个数组对象,简单的理解为一个函数定义了4个形参,执行这个函数时传递了4个实参,那么arguments.length的值为4,如果传了3个实参,那么arguments.length的值为3,通过arguments[i]可以访问具体哪个实参的值,如arguments[1]得到第二个实参的值
总结以下实例便于记忆:

function test(a,b,c,d){//定义了4个形参

        console.log(arguments);//[1, 2, 3]
        console.log(typeof arguments);//object
        console.log(arguments[1]);//2
        console.log(arguments.length);//3
}

test(1,2,3);//传了3个实参

  



原文地址:https://www.cnblogs.com/rapale/p/5075523.html