Within an array of objects, I have a structure like this:
"times": [{
"id" : "id",
"name" : "place",
"location" : "place",
"hours" : [
{"day": "Sunday", "day_id": 0,
"tags": "" },
{"day": "Monday", "day_id": 1,
"tags": "" },
{"day": "Tuesday", "day_id": 2,
"tags": "" },
{"day": "Wednesday", "day_id": 3,
"tags": "" },
{"day": "Thursday", "day_id": 4,
"tags": "" },
{"day": "Friday", "day_id": 5,
"tags": "" },
{"day": "Saturday", "day_id": 6,
"tags": "" }
]
}
]
My goal is to extract specific data from the hours array within each object.
I am attempting to identify and retrieve objects that match a particular day_id in the hours array.
My initial attempt was this:
let f1 = times.filter((item: { id: string; hours: { day_id : number;};}) => item.hours.day_id == 0 );
However, this approach did not yield the desired result. What mistake am I making here?