I am implementing a filter. it works fine. the problem is it's just matching a single object value instead of all value matching.
Matching means here is, let it be contain any single letter in the value
example: here is my object
{name:"D",color:"Green",size:50}
in case if i pass the filter object as :
let filter1 = {color:"Blu",size:'50'};
at present I am getting single result by matching size. But the color is not matching at all. so the result should be empty.
How to mach all values in the object and get the filtered value.
Code :
const nestedFilter = (targetArray, filters) => targetArray.filter(o => Object.keys(filters).find(k => filters[k].includes(o[k])));
let products = [
{name:"A",color:"Blue",size:70},
{name:"B",color:"Blue",size:60},
{name:"C",color:"Black",size:70},
{name:"D",color:"Green",size:50}
];
let filter1 = {color:"Blu",size:'50'};
console.log(nestedFilter(products, filter1));