Array is not Pushing Data

for(let i=0; i<=this.data_a.demo.length; i++)
      {
     this.finalalue.push(this.data_a.demo[i].category);
      }

It’s this.finalalue.push(this.data_a.demo[i].category); showing an error

_this.data_a.demo[i] is undefined

Please help me out.

Your loop isn’t correct, you try to access a value over the array length

Bad:

 for(let i=0; i<=this.data_a.demo.length; i++)

Good:

for(let i=0; i<this.data_a.demo.length; i++)

Assuming data is there…

 this.finalvalue = this.data_a.demo.map(d => d.category);
2 Likes