Currently, I am attempting to develop a filter function that will return data matching the specified value from a given set of string keys.
Here is an example of an array:
let data = [
{ id:1 , data:{ name:"sample1",address:{ cat:"business" } } },
{ id:2 , data:{ name:"sample2",address:{ cat:"office" } } },
{ id:3 , data:{ name:"sample3",address:{ cat:"office" } } },
{ id:4 , data:{ name:"sample4",address:{ cat:"office" } } }
{ id:5 , data:{ name:"sample5",address:{ cat:"home" } } }
{ id:6 , data:{ name:"sample6",address:{ cat:"home" } } }
]
function createFilter( collection , value ,key ){
//insert code here
}
let result = createFilter( data , "business" , [ "data","address","cat" ] )
console.log(result)
The expected output is:
{ id:1 , data:{ name:"sample1",address:{ cat:"business" } } },