I have an array containing objects which contains an array also containing objects. When the object in the array inside the array of objects contains a value of 111 I want to return the whole object inside the first array.
The code below shows one example object in the first array.
[
{
"id":11,
"bookingNumber":"1210",
"arrivalDate":"2018-09-17T22:00:00.000Z",
"departureDate":"2019-09-18T22:00:00.000Z",
"customerId":2,
"fields":[
{
"value":"111",
"display_name":"RoomNumber"
},
{
"value":"otherValue",
"display_name":"PersonInfo"
}
]
}
]
My try which returns undefined:
const guest = guestGroups.forEach(function (guestGroup) {
guestGroup.fields.filter(function (fields) {
if (fields.value === roomNumber)
return guestGroup;
});
});