Suppose I have object
let x = { "people" :{
"Sally": "value",
"Bob" : "other value"
},
"cars" :{
"Saab" : "this",
"Chevy": "that"
},
"trees":{
"Birch" : "what",
"Oak" : "where"
}
}
I want to search, so if I searched for "S" I'd get back an array that was
{ "people" :{
"Sally": "value",
},
"cars" :{
"Saab" : "this",
}
}
And if I searched for "b" I'd get:
{ "people" :{
"Bob" : "other value"
},
"trees":{
"Birch" : "what",
}
}
or "bo" would return
{ "people" :{
"Bob" : "other value"
}
And if I searched "e" I'd get
{ "cars" :{
"Chevy": "that"
}
}
Note that the "people" and "trees" isn't caught by the search for 'e'.
The strut will be of a fixed depth, and we only ever want to catch keys that match the filter and don't have children (we're also not interested in values that match, just keys).
Adding npm dependencies is acceptable.
Attempted solution:
filteredList(unfiltered,searchVal) {
return unfiltered.filter(search=> {
return search.toLowerCase().includes(searchVal.toLowerCase())
})
}
Obviously there's more to it, but I'm not sure which direction to proceed.
filteris an method of arrays. You have an object.