1

I have array productData with 69 elements and productDatagreen with 659 elements in angular application. When I do push all the 659 elements are going inside index 69 same thing happening cancat. Then I have total length of array 70.

I need length of array 69+659 and items should be in same row. How can I do that. This is my code.

this.productData.push(this.productDatagreen)
this.productData= this.productData.concat([this.productDatagreen])    
this.mapImageSeries.data=this.productData;
this.Chart.validateData();

Array screenshot

enter image description here

R15
  • 13,982
  • 14
  • 97
  • 173
  • Try `this.productData.push(...this.productDatagreen)` or `this.productData = this.productData.concat(this.productDatagreen)` – Phil Oct 09 '20 at 05:44
  • Does this answer your question? [How to append something to an array?](https://stackoverflow.com/questions/351409/how-to-append-something-to-an-array) – Phil Oct 09 '20 at 05:49
  • @Phil - Your first line of code worked for me with ... dots. – R15 Oct 09 '20 at 05:50
  • They should both work. Feel free to close this as a duplicate since both methods our outlined in the linked post – Phil Oct 09 '20 at 05:51
  • @Phil - You can write it as a answer. I have seen many threads. There is not easy to find. Need to scroll total page and make changes execute your project if not working repeat the same. – R15 Oct 09 '20 at 05:53
  • did u try this ?`this.productData =[...this.productData,...productDatagreen]` – Beingnin Oct 09 '20 at 06:59

2 Answers2

1

As per the @phil's comment.

this.productData.push(...this.productDatagreen)

Worked for me.

R15
  • 13,982
  • 14
  • 97
  • 173
1

You could do something like this

this.productData =[...this.productData,...this.productDatagreen]
console.log(this.productData.length);//will console 728
Beingnin
  • 2,288
  • 1
  • 21
  • 37