I have array of objects that include children from the array of objects and i need to find value inside parent array or find value inside childrens of this array etc. Maybe recursive. I trided like this:
var array = [
{
id: 1,
value: 'value',
children: null
},
{
id: 2,
value: 'my value',
children: [
{
id: 'child1',
value: 'my value',
children: null
},
{
id: 'child2',
value: 'value',
children: null
},
{
id: 'child3',
value: 'value,
children: [
{
id: 'childchild1',
value: 'my value',
children: null
}
]
}
]
},
{
id: 3,
value: 'value',
children: null
},
{
id: 4,
value: 'my value',
children: null
}
]
function find(searchData, target){
return target.filter((f)=>{
if(f.value.includes(searchData)){
return true
}
if(f.children){
return find(searchData, f.children)
}
})
}
find('my', array)
It's returns source array but i need array which includes text 'my'