js中arguments详解

 

 

 

 

1.当形参 数量不确定时,可以通过arguments对象获取传参的值。(为一个数组)

            function max(a) {
		     console.log(a);
		        var max = arguments[0];
		        console.log(arguments);//传入形参的值,数组形式。
		
		        for (val of arguments) {
		            if (val >= max) {
		                max = val;
		            }
		        }
		        return max;
		    }
		    var maxValue = max(1, 2, 4)
		    console.log(maxValue);  // 输出4

  

 

相关文章:

  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-05-17
  • 2022-12-23
  • 2021-08-13
猜你喜欢
  • 2022-01-16
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-01-26
  • 2021-11-25
  • 2021-05-05
相关资源
相似解决方案