簡體   English   中英

如何按現有元素的相同順序推送數組元素

[英]How to push array elements in the same order of existing elements

我在angular應用程序中有包含 69 個元素的數組productData和包含 659 個元素的productDatagreen 當我push時,所有 659 個元素都進入索引 69 中,同樣的事情發生cancat 然后我的數組總length為 70。

我需要數組的length 69+659 並且項目應該在同一行中。 我怎樣才能做到這一點。 這是我的代碼。

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

數組截圖

在此處輸入圖像描述

根據@phil 的評論。

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

為我工作。

你可以這樣做

this.productData =[...this.productData,...this.productDatagreen]
console.log(this.productData.length);//will console 728

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM