undefinedfix
Sign in

In the judgment of if condition, this.listArrTwo [index]. Areaname indicates that areaname is undefined

TheValyreanGroup edited in Sat, 23 Jul 2022

In the if condition judgment, this . listArrTwo [ index ]. Areaname means that areaname is undefined

      this.listArr.forEach((item, index) => {
        if(this.listArrTwo[index].areaName ) {
          item.areaNameT = this.listArrTwo[index].areaName
          item.stotalT = this.listArrTwo[index].stotal
          item.ctotalT = this.listArrTwo[index].ctotal
        }
      })

That is to say, the areaname in the if condition is undefined. At the last time of the loop, there is no key of areaname, so if undefined is declared, I will add one this.listArrTwo [index].areaName ! ==Undefined also reports errors. Why

2 Replies
DGrist
commented on Sat, 23 Jul 2022
this.listArr.forEach((item, index) => {
        if(this.listArrTwo[index] && this.listArrTwo[index].areaName ) {
          item.areaNameT = this.listArrTwo[index].areaName
          item.stotalT = this.listArrTwo[index].stotal
          item.ctotalT = this.listArrTwo[index].ctotal
        }
      })

How about this

Chuck
commented on Sat, 23 Jul 2022

Next time you answer a question, post your code and error message.

You can't report areaname here. It's undefined. You can only report it this.listArrTwo [index] is undefined. The reason for this error may be that the length of listarrtwo array is not enough, so the index overflows and gets the this.listArrTwo [index] is undefined. Undefined will throw an error when it takes a property value.