js数组的插入和删除

1、你需要添加一个或多个要添加到数组末尾的元素push。

2、从数组中删除最后一个元素的话直接使用 pop() 就可以。

3、unshift() 和 shift() 从功能上与 push() 和 pop()只是它们分别作用于数组的开始,而不是结尾。

var myArray = ['Manchester', 'London', 'Liverpool', 'Birmingham', 'Leeds', 'Carlisle']
myArray.push('张三')
console.log(myArray)  //["Manchester", "London", "Liverpool", "Birmingham", "Leeds", "Carlisle", "张三"]
        
myArray.pop()
console.log(myArray)  //["Manchester", "London", "Liverpool", "Birmingham", "Leeds", "Carlisle"]

myArray.unshift('Edinburgh');
console.log(myArray)  //["Edinburgh", "Manchester", "London", "Liverpool", "Birmingham", "Leeds", "Carlisle"]

myArray.shift()
console.log(myArray)  //["Manchester", "London", "Liverpool", "Birmingham", "Leeds", "Carlisle"]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值