//this.arr=[1,2,3,4,5,6]
//this.add=[2,5,6,9]
1.concat()合并兩個數(shù)組:
let a=[];
a=this.arr.concat(this.add);
console.log(a)//[1, 2, 3, 4, 5, 6, 2, 5, 6, 9]
2.join('')將數(shù)組轉(zhuǎn)為字符串,使用指定符號分割
console.log(this.arr.join('|'))//1|2|3|4|5|6
3.pop()刪除并返回數(shù)組中的最后一個元素
console.log(this.arr.pop())//6
4.push()向末尾添加一個或多個元素并返回新的長度
console.log(this.arr.push(2,5,6,8,4))//?[1, 2, 3, 4, 5, 6, 2, 5, 6, 8, 4]
5.reverse()使數(shù)組中的元素倒序
console.log(this.arr.reverse())//[6, 5, 4, 3, 2, 1]
6.shift()刪除數(shù)組中的第一個元素并返回
console.log(this.arr.shift())//1
7.slice()返回指定之間的元素,如果是一個參數(shù)就返回它后面的,如果是a,f就返回c到f
console.log(this.arr.slice(2,5))//3,4,5
8.splice(index,num)有兩個參數(shù)index是下標(biāo),num是從index開始刪除幾個,并返回刪除的元素
console.log(this.arr.splice(3,2))//4,5
9.toString()//將數(shù)組轉(zhuǎn)為字符串并返回結(jié)果
console.log(this.arr.toString())//1,2,3,4,5,6
10.unshift()向數(shù)組的開頭添加一個或多個元素并返回新的長度
console.log(this.arr.unshift(1,2))//8
11.sort()排序比如:arr:[6,7,2,1,9,6,8],arr.sort()//
console.log(this.arr.sort(arr))//[9, 8, 7, 6, 6, 2, 1]
function arr(a,b){
return b-a;//從大到小
}