There is an array of objects with nested objects. When searching, you need to display all requested results and their parents
const data = [{
"title": "News",
"children": [{
"title": "News1"
}, {
"title": "News2",
"children": [{
"title": "News22"
}, {
"title": "News23"
}]
}]
}, {
"title": "Works"
}]
const handleInput = () => {
return filteredData = data.filter(item => {
let itemTitle = item.title.toLowerCase();
return itemTitle.includes(searchValue.toLowerCase())
});
}
example image
example image1
Expected output:
example image3
New contributor
Andrei Alisenok is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.