I am trying to loop through an object that contains arrays which contain objects inside of them in React and I get an error on the .map function. Here is the .map function followed by what the object looks like in this.state
.map:
//trying to access January from the object which is 0 starting month
let daysOfWeeks = this.state[0].map(function (day, i){
...
}
Here is an example of the object:
//0 is January, 1 is February, and so on... inside has objects that have the day number and day of week
let result = {
0:[
{dayNumber:1,dayOfWeek:"fri"},
{dayNumber:2,dayOfWeek:"sat"},
{dayNumber:3,dayOfWeek:"sun"},
...
],
1:[
{dayNumber:1,dayOfWeek:"mon"},
{dayNumber:2,dayOfWeek:"tue"},
{dayNumber:3,dayOfWeek:"wed"},
...
],
2:[
{dayNumber:1,dayOfWeek:"tue"},
{dayNumber:2,dayOfWeek:"wed"},
{dayNumber:3,dayOfWeek:"thur"},
...
],
...
};
//result is in a function that is returned and set state is calling the function and setting state to the object itself -- here is setState:
this.setState(getDaysArray(y,m));
//getDaysArray(y,m) returns that object above
What I want in the .map is for day to be the object I loop through. day.dayNumber and day.dayOfWeek
... .map(function(day, i){
return(
<div>
<div>{day.dayNumber}</div>
<div>{day.dayOfWeek}</div>
</div>
)
}
But what errors in on the .map is this.state[0] I think is the issue. Anyone know how I can access and loop through the objects in the array inside the parent object?