我遍历数组,让数组内两两相加后log出来的数组显示对的,但是每个index对应的值不一样,这是为什么
原数组(73)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 60, 85, 125, 0, 0, 40, 110, 0, 70, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 110]
遍历后数组(38) [0, 0, 0, 0, 0, 0, 0, 40, 145, 125, 40, 110, 180, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 110, 0, ob: Observer]
0: 0
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 40
9: 0
10: 60
11: 0
12: 85
13: 0
14: 0
15: 0
16: 0
17: 0
18: 125
19: 0
20: 0
21: 0
22: 0
23: 0
24: 40
25: 0
26: 0
27: 0
28: 0
29: 0
30: 0
31: 0
32: 0
33: 0
34: 0
35: 0
36: 110
37: 0
代码
//定义x轴数组
const xAxisTen = [].concat(this.xAixsTimeData)
const xAixsTenMinute = xAxisTen.filter((value,index)=>{
if(index%2===0){
return true
}
})
this.xAixsTotalData = xAixsTenMinute
console.log('10 xz',this.xAixsTotalData)
//总乘客
const tenMinuteTotal = [].concat(this.resTotalPassenger)
console.log('123',tenMinuteTotal)
let resTotal = []
let resTotalHead = tenMinuteTotal[0]
tenMinuteTotal.filter((item,index,arr)=>{
if(index%2 ===0){
let sumTotal = (arr[index+1]||0)+(arr[index+2]||0);
resTotal.push(sumTotal)
}
})
resTotal.unshift(resTotalHead)
this.resTotalPassenger =[]
this.resTotalPassenger = [].concat(resTotal)
console.log('10 total',this.resTotalPassenger)
//出站乘客
const tenMinuteOut = [].concat(this.resOutPassenger)
let resOut = []
let resOutHead = tenMinuteOut[0]
tenMinuteOut.filter((item,index,arr)=>{
if(index%2 ===0){
let sumOut = (arr[index+1]|| 0)+(arr[index+2]||0);
resOut.push(sumOut)
}
})
resOut.unshift(resOutHead)
this.resOutPassenger =[]
this.resOutPassenger = [].concat(resOut)
console.log('10 out',this.resOutPassenger)
//定义 进入的乘客相加
const tenMinuteIn = [].concat(this.resInPassenger)
let resIn = []
let resInHead = tenMinuteIn[0]
tenMinuteIn.filter((item,index,arr)=>{
if(index%2 ===0){
let sum = (arr[index+1]|| 0)+(arr[index+2]||0);
resIn.push(sum)
}
})
resIn.unshift(resInHead)
//console.log(this.resInPassenger)
this.resInPassenger =[]
this.resInPassenger = [].concat(resIn)
console.log('10 in',this.resInPassenger)
this.drawPassengerChart()