简体   繁体   中英

How to push dynamic value in array?

I have to push dynamic value in data

  lineChartData: ChartDataSets[] = [
    { data: [], label: 'prices are' },
  ];

From my method I am pushing values as:

for(let e of x){
      
      this.lineChartData.push(e.raise)
     
    };

How can I push value in data[]?

you are having nested array/ so you need to run for loop twice

for eg

myArr = [{data:[]}]

for(let i of myArr){
  i.data.push('a');
}

I am passing string you can pass your object/array

using your example object

lineChartData: ChartDataSets[] = [
    { data: [], label: 'prices are' },
  ];

for(let i of lineChartData){
    i.data.push(yourObject)
 
}

How can I push value in data[]?

Use

lineChartData[0].data.push(e.raise);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM