let NewList = []//新建空数组
let NewLength = this.ProcessList.length//ProcessList旧数组
if (NewLength % 2 != 0) {//去余不为0的时候(奇数)
for (var i = 0; i < (NewLength - 1) / 2; i++) {//
let newItem = {}
newItem = this.ProcessList[i + i]
newItem.NewHistoryActivityName = this.ProcessList[i + 1 + i].historyActivityName
NewList.push(newItem)
}
console.log(222, NewList)
let newItem = {}
newItem = this.ProcessList[this.ProcessList.length - 1]
NewList.push(newItem)
console.log(3333, NewList)
} else if (NewLength % 2 == 0) {//去余为0的时候(偶数)
for (var i = 0; i < NewLength / 2; i++) {
let newItem = {}
newItem = this.ProcessList[i + i]
newItem.NewHistoryActivityName = this.ProcessList[i + 1 + i].historyActivityName
NewList.push(newItem)
}
console.log(444, NewList)
}
this.NewList1=NewList
console.log('111', this.ProcessList)
数组中相邻对象进行合并,并取奇数中某字段为偶所用(奇偶区分)
最新推荐文章于 2024-08-09 10:42:44 发布