Can you assist with this issue?
I am trying to filter the items in an array based on certain activities in their object array. Below is the code snippet:
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 provided as a string, the expected output 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}]
}]