I have the following parsed JSON response from an API
emp =
{
"response": [
{
"image_fingerprint": null,
"image_source_fingerprint": null,
"last_name": "LastName",
"location": "G564",
"notes": "A great worker",
"online_seating": {
"seat_urls": []
},
"photo": "/images/employee.jpg",
"seating": {
"seated": "not seated",
"seat_urls": [
"/api/1/seats/33444",
"/api/1/seats/55323",
"/api/1/seats/62229"
]
},
"show_in_vd": true,
"start_date": "2014-01-02",
},
{
"image_fingerprint": null,
"image_source_fingerprint": null,
"last_name": "LastName",
"location": "G564",
"notes": "A great worker",
"online_seating": {
"seat_urls": []
},
"photo": "/images/employee.jpg",
"seating": {
"seated": "not seated",
"seat_urls": [
"/api/1/seats/56580",
"/api/1/seats/69856",
"/api/1/seats/50003"
]
},
"show_in_vd": true,
"start_date": "2014-01-02",
}
]
}
I need to compare the array seat_urls that is inside that response to the following array
shiftA = ["/api/1/seats/50003","/api/1/seats/62229", "/api/1/seats/556565"]
And return all the data from emp if any of the URLs in shiftA matches the URLs in emp.seat_urls
I have tried
var shiftAEmp = emp.seating.seat_urls.filter(value => shiftA.includes(value))
and many others but I keep getting TypeError: Cannot read property 'seat_urls' of undefined
I tried other filter approaches with no luck it just seam I can't access the seat_urls inside the JSON file emp (sometimes seats_urls cab=n be empty by the way)
Any help will be appreciated
Thanks
emp.responseit will work for you.https://codepen.io/sibabrat_swain/pen/RwrWMeJcheck your console.