could you help with these problem.
I need to filter the items in the array that contains certains activities in their object array. Heres is the code:
let userArray = [{
name: "alonso",
age:16,
hobbies: [{activity:"videogames", id: 1}, {activity:"watch tv", id:2}]
},
{
name: "aaron",
age:19,
hobbies: [{activity:"videogames", id:1}, {activity:"soccer", id:8}]
},
{
name: "Luis",
age:27,
hobbies: [{activity:"code", id:3}, {activity:"soccer", id:8}]
}]
if "videogames" is passed by string the output expected is:
[{
name: "alonso",
age:16,
hobbies: [{activity:"videogames", id: 1}, {activity:"watch tv", id:2}]
},
{
name: "aaron",
age:19,
hobbies: [{activity:"videogames", id:1}, {activity:"soccer", id:8}]
}]
Array.some()method in the filter callback function.people.filter(person => person.hobbies.find(hobby => hobby.activity === someActivity))