1、push() 尾端插入,返回数组长度
let arr = [1,"hello",true];
console.log(arr.push(22));//4
console.log(arr,'---arr');//[1, "hello", true, 22]
console.log(arr.push(false,123));//6
console.log(arr,'---arr2');//[1, "hello", true, 22, false, 123]
console.log(arr.push(["a","b"]));//7
console.log(arr,'---arr3');//[1, "hello", true, 22, false, 123, ["a","b"]]
2、pop() 尾端移除,返回移除项
let arr = [2,"hello",true];
console.log(arr.pop());//true
console.log(arr,'---arr');//[2, "hello"]
//里面无需加参数,加参数没用
console.log(arr.pop(0));//hello
console.log(arr,'---arr2');//[2]
3、shift() 首端移除,返回移除项
let arr = [1,"hello",true];
console.log(arr.shift());//1
console.log(arr,'---arr');//["hello", true]
4、unshift() 首端插入,返回数组长度
let arr = [1,"hello",true];
console.log(arr.unshift(false,123));//5
console.log(arr,'---arr');//[false, 123, 1, "hello", true]
console.log(arr.unshift());//5
console.log(arr,'---arr2');//[false, 123, 1, "hello", true]
5、利用拓展运算符(...)可实现在数组前中后插入数据
let arr = [2,"hello",true];
var arr2 = [...arr,"a",...arr,"b",...arr]
console.log(arr2)// [2, "hello", true, "a", 2, "hello", true, "b", 2, "hello", true]