Reputation: 67
myData = [{
"Total_Demand": "800",
"weekly": [
{
"CycleTime": .65,
"Demand": 650,
},
{
"CycleTime": .75,
"Demand": 820,
}
]
}]
if i do console.log("The Data of weekly is", this.myData[0].weekly[0]);
I'm able to get the data object but not able to iterate
for(let i=0; i > this.myData[0].weekly.length; i++) {
this.WeeklyData = [this.myData[0].weekly[i]].push(this.WeeklyData);
}
WeeklyData is not having data it is showing as undefined
Upvotes: 0
Views: 77
Reputation: 1154
Please try this I hope it's helpful.
it's ES6 standard.
Thanks
for(let i=0; i < this.myData[0].weekly.length; i++) {
this.WeeklyData = [...this.WeeklyData,this.myData[0].weekly[i]]
}
Upvotes: 0
Reputation: 10078
You have it reversed... it should be
this.WeeklyData = [];
for(let i=0; i <= this.myData[0].weekly.length; i++) {
this.WeeklyData.push(this.myData[0].weekly[i]);
}
And, of course you have i >
where it should be i <=
You can also push the whole array, as in
this.WeeklyData.push(this.myData[0].weekly);
Upvotes: 0
Reputation: 5529
Can you try this
this.WeeklyData = [...this.myData[0].weekly[i], ...this.WeeklyData];
Upvotes: 1