How to filter an object given its partial path?
As an example.
let address = {
country :{
name:'Japan',
city:{
name:'Tokyo',
town: {
name:'korushawa'
}
},
code:'JP'
},
nearbyCountry:'Korea'
}
path1: countr.cit
For address
, path1 will result in
{
country :{
city:{
name:'Tokyo',
town: {
name:'korushawa'
}
}
}
}
path2: countr
For path2,
I should get entire address
object because countr is present in country
and nearbyCountry
{
country :{
name:'Japan',
city:{
name:'Tokyo',
town: {
name:'korushawa'
}
}
},
nearbyCountry:'Korea'
}
Edit: I have been able to solve this when given an exact path (ex: country.city
). But having difficulty with partial paths.