arguments表明的是實參。有個講究的地方是:arguments只在函數中使用。數組
(1)返回函數實參的個數:arguments.length函數
例子:spa
fn(2,4); fn(2,4,6); fn(2,4,6,8); function fn(a,b,c) { console.log(arguments); console.log(fn.length); //獲取形參的個數 console.log(arguments.length); //獲取實參的個數 console.log("----------------"); }
結果:code
(2)之因此說arguments是僞數組,是由於:arguments能夠修改元素,但不能改變數組的長短。舉例:blog
fn(2,4); fn(2,4,6); fn(2,4,6,8); function fn(a,b) { arguments[0] = 99; //將實參的第一個數改成99 arguments.push(8); //此方法不經過,由於沒法增長元素 }
清空數組的幾種方式:io
var array = [1,2,3,4,5,6]; array.splice(0); //方式1:刪除數組中全部項目 array.length = 0; //方式1:length屬性能夠賦值,在其它語言中length是隻讀 array = []; //方式3:推薦