Struggling to access a specific value of an object within an array? I need your assistance. My goal is to showcase each value of the key "hours" in the object called NumberR, and then display 11am and 7pm on my Angular frontend. Here's the JSON returned by the API:
{
"reservations": {
"reservationInfo": [
{
"roomStay": {
"arrivalDate": "11am"
},
"WeatherR": {
"sound": "cloudy"
},
},
{
"roomStay": {
"arrivalDate": "7pm"
},
"WeatherR": {
"sound": "cloudy"
},
}
]
}
}
In app.component.ts file:
searchForReservation() {
alert('hello');
this.http.get('/api/searchForReservation').subscribe((res) => {
this.dataInfo = res;
console.log('MY DATA', this.dataInfo);
this.uniqueDates = this.dataInfo.reservations.reservationInfo.map(
(e) => e.roomStay.arrivalDate
);
});
}
In component.html:
<div class="test">
<p>Arrival Date:</p><p>{{this.date}}</p>
</div>