uniapp 数组遍历组成新数组map,数组过滤filter,删除数组某一项findIndex,添加push
数组遍历组成新数组,用数组方法map,数组过滤filter,删除数组中重复的某一项findIndex,不重复的就push到新数组中
·
数组遍历组成新数组,用数组方法map,
const _this = this
var duoxuanshuzu = []
_this.listright.map((item, index) => {
duoxuanshuzu.push(
//重新加属性建数组,符合组件的要求
Object.assign({
id: index
}, {
tag: item
})
)
})
console.log(duoxuanshuzu)
数组过滤filter,删除数组中重复的某一项findIndex,不重复的就push到新数组中
change(item) {
// console.log(item)
this.id = item.id
if (this.ids.includes(this.id)) {
// id数组filter方法
this.ids = this.ids.filter(item => {
return item != this.id
})
console.log('id=>', this.id)
// choice数组,重复点击删除此项
var index0 = this.choice.findIndex(item => {
if (item.id == this.id) {
return true
}
})
this.choice.splice(index0, 1)
} else {
this.ids.push(this.id);
this.choice.push(item.tag);
}
}
更多推荐
已为社区贡献10条内容
所有评论(0)