a pleasure to greet you, I need someone's help please:
It turns out that I have an object and inside it there is an array of objects. How should I go through it?
The object is something like this:
{
"afiliado":
{
"attentionSchedules": [
{
"room": "x",
"floor": 2,
"schedules": [
{
"days": [
"MO",
"TU",
"FR",
"TH",
"WE"
],
"_id": "xxxxx",
"initialTimeStr": "07:00 am",
"finalTimeStr": "04:00 pm",
"initialTime": "2020-11-12T13:00:00.000Z",
"finalTime": "2020-11-12T22:00:00.000Z"
}
],
room: {[]}
]
}
}
I want to access initialTimeStr and finalTimeStr how can I loop through this object and filter this data in angular?
I already managed to map the array:
I did it with:
console.log('hour :>>', this.bookingService.bookingModel.affiliate?.attentionSchedules.map(schedule => schedule.schedules ))
But I don't know how to extract "initialTimeStr" and "finalTimeStr" can someone help me?
Manually, you can do this.
You can automate it with
forEach
:I imagine you have that answer saved in some array like
first of all I suggest you to avoid the use of any, and use a correct typing of your response, in case you don't know what type it is, you can copy the response in this url: https://app.quicktype.io/ and then create an interface file like this for example:
schedule.interface.ts
with the typing obtained on the site.Then your arrangement would look like this
schedules:Schedule[] =[]
you could perfectly get your records
example of a list in your html:
Destructuring Theory for Destructuring