I’m creating a function to search information in a json structure, my function works well in the first level but I have problems to search in the second level. My funtion return all the object json as if the search had never been performed.
this is my code:
json:
let machine = [
{
"sku": "qweert-12",
"type": "aaaa",
"components":[
{
"unit": "mmmm",
"sku": "qwer-12"
},
{
"unit": "llll",
"sku": "qwer-14"
}
]
},
{
"sku": "qmqert-12",
"type": "bbbb",
"components":[
{
"unit": "ssss",
"sku": "qwlr-12"
},
{
"unit": "jjjj",
"sku": "qwuer-14"
}
]
},
]
function
const search= (inputUser, data, setReturninfo) => {
const input = inputUser.target.value();
const result = data.filter((data) => {
let component= data.components;
return Object.keys(component).some((key) => {
return JSON.stringify((data[key])).toLocaleLowerCase().trim.includes(input);
})
});
setReturninfo(result);
}
I appreciate any help.