js-向数组添加元素

unshift-添加到数组的头部

shift-删除数组的头部

push-添加数组尾部

pop-删除数组尾部

var fruits = ["Banner","Apple","Pear"];
fruits.pop();
console.log(fruits)

//运行结果
banner,apple


var fruits = ["Banner","Apple","Pear"];
fruits.push("Lemon","Mango");
console.log(fruits)

//运行结果
Banner,Apple,Pear,Lemon,Mango


var fruits = ["Banner","Apple","Pear"];
fruits.unshift("Lemon","Mango");
console.log(fruits)

//运行结果
Lemon,Mango,Banner,Apple,Pear

var fruits = ["Banner","Apple","Pear"];
fruits.shift();
Apple,Pear


 

你可能感兴趣的:(js)