一捅伤、concat():連接兩個或更多數(shù)組
var arr1 = new Array("1","2","3");
var arr2 = new Array("4","5","6");
console.log(arr1.concat(arr2)); //輸出結(jié)果:["1", "2", "3", "4", "5", "6"]
二、pop():刪除并返回數(shù)組最后一個元素
var arr = new Array("1","2","3");
console.log(arr.pop()); //輸出結(jié)果:3
三祠汇、shift():刪除并返回數(shù)組第一個元素
var arr = new Array("1","2","3");
console.log(arr.shift()); //輸出結(jié)果:1
四熄诡、push():在數(shù)組最后添加一個或多個元素
var arr = new Array("1","2","3");
console.log(arr.push("4","5","6")); //輸出結(jié)果:6
注:返回值為新數(shù)組長度
五凰浮、unshift():在數(shù)組開頭添加一個或多個元素
var arr = new Array("1","2","3");
console.log(arr.unshift("4","5","6")); //輸出結(jié)果:6
注:返回值為新數(shù)組長度
六苇本、splice():刪除并添加新元素
splice("添加元素的位置","從添加位置開始刪除元素的個數(shù)【0為不刪除】","要添加的元素【不填時相當(dāng)于只刪除元素】")
var arr = new Array("1","2","3");
console.log(arr.splice(1,1,4)); //輸出結(jié)果:2
console.log(arr.splice(1,2)); //輸出結(jié)果:2,3
注:返回值為刪除的元素
七菜拓、reverse():數(shù)組按下標(biāo)倒敘排列
var arr = new Array("1","0","3");
console.log(arr.reverse()); //輸出結(jié)果:["3", "0", "1"]
八纳鼎、sort():數(shù)組元素排序
var arr1 = new Array(1,0,3);
var arr2 = new Array("1","0","3");
var arr3 = new Array("a","c","b");
var arr4 = new Array("Z","z","a");
var arr5 = new Array("Z","a",2);
console.log(arr1.sort()); //輸出結(jié)果:[0, 1, 3]
console.log(arr2.sort()); //輸出結(jié)果:["0", "1", "3"]
console.log(arr3.sort()); //輸出結(jié)果:["a", "b", "c"]
console.log(arr4.sort());?//輸出結(jié)果:["Z", "a", "z"]
console.log(arr5.sort()); //輸出結(jié)果:[2, "Z", "a"]
八贱鄙、slice():返回數(shù)組中指定元素
slice("起始位置[為負(fù)值時反向開始,如-1代表最后一個元素]","結(jié)束位置[不填時為從起始位置截取到最后]")
var arr = new Array("1","2","3","4","5","6");
console.log(arr.slice(2,5)); //輸出結(jié)果:["3", "4", "5"]
注:截取時不包括最后一位
九悬荣、join():數(shù)組轉(zhuǎn)成字符串并用制定字符連接
var arr = new Array("a","b","c");
console.log(arr.join()); //輸出結(jié)果:a,b,c
console.log(arr.join("+")); //輸出結(jié)果:a+b+c
十疙剑、toString():數(shù)組轉(zhuǎn)字符串
var arr = new Array("a","b","c");
console.log(arr.toString()); //輸出結(jié)果:a,b,c