0
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

3 Answers 3

1

Can you try this

this.WeeklyData = [...this.myData[0].weekly[i], ...this.WeeklyData];
Sign up to request clarification or add additional context in comments.

2 Comments

this.WeeklyData is declared as any type and assigned empty array. this.WeeklyData = [];
ahh, hint's in @Felix answer, i > should be i <, and you can apply my ans
0

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);

Comments

0

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]]
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.