一、添加 数组添加元素的两个方法(都不去重) 1、数组.push(对象) 直接向数组末尾追加新的元素(不会去重) //this.productTemporary=[]this.productTemporary.push(e);
直接向数组末尾追加新的元素(不会去重)
//this.productTemporary=[]this.productTemporary.push(e);
使用push添加数组时会将整个数组直接加入数组之中
使用concat会将要追加的数据(数组)进行拆分以此追加到数据末尾
//this.products=[]this.products = this.products.concat(res.result.items); //追加新数据
追加相同的数据
追加一组数组
3.数组去重
//arr:需要被去重的数组res = new Map();v = arr.filter(arr => !res.has(arr.productId) && res.set(arr.productId, arr.productId));
使用splice删除元素
删除数组中的元素(通过找出该对象的下标来删除);index ==-1表示数组为空
// this.productTemporary数组//item需要删除的元素const index = this.productTemporary.findIndex(i => i == item)if (index != -1) {this.productTemporary.splice(index, 1)}
来源地址:https://blog.csdn.net/qq_44774287/article/details/127508777
--结束END--
本文标题: 微信小程序数组对象的添加及删除(Vue2)
本文链接: https://www.lsjlt.com/news/372342.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0