For example if I wanted to get a new array of all objects that had a skill of "reading" from the below array, how would I do this?
I tried testResult but just get infinite loop :(
Thanks for all and any help!
const people = [{
name: "Jon",
skills: ["reading", "acting", "drinking"],
},
{
name: "Tim",
skills: ["rowing", "hockey", "reading"],
},
{
name: "Lucy",
skills: ["business", "learning", "hockey"],
},
{
name: "Michelle",
skills: ["running", "business", "sleeping"],
},
{
name: "Michael",
skills: ["making friends", "surfing"],
}
]
Expected return:
[{
name: "Jon",
skills: ["reading", "acting", "drinking"],
},
{
name: "Tim",
skills: ["rowing", "hockey", "reading"],
}]
const testResult = testArray.map((obj) => {
obj.skills.map((skill) => {
if (skill === "reading") {
setPeople([...people, obj])
}
})
})