0

Below are my data array and multiple search keys to search the data array.

let dataStore = [
{
  fName: "Sachin",
  level: ["L1"],
  position: "Cricket",
},
{
  fName: "Michale",
  level: ["L1", "L2"],
  position: "Football"
},
{
  fName: "Smith",
  level: ["L3"],
  position: "Carrom"
},
{
  fName: "Lara",
  level: "L3",
  position: "Chess"
},
{
  fName: "Rose",
  level: "L5",
  position: "Swimming"
}
]

let searchByThis = {
    position: ["Cricket", "Chess"],
    level: "L1",
    fName: "Lara"
}

Need to filter the dataStore array by the searchByThis object. It should return the result to all matching scenario. I have tried with find, filter but not getting the correct result for the above example. The search object, dataStore array may have array also sometimes.(example: position). Any way to find particular object by its key?

GTemp
  • 149
  • 1
  • 9
  • 1
    please add your try. – Nina Scholz Aug 23 '21 at 17:02
  • Say `i` is `searchByThis`, you want all items that match `i.position AND i.level AND i.fName`, or the ones that match `i.position OR i.level OR i.fName`? Say `i` has an array (e.g. `i.position`), you want all the items whose `position` can be found in `i.position`? If `i.level` were an array, how would you match items that have an array as `level` too? For example, with `i.level = ["L1", "L3"]`, would `Michale` be matched, and why? – sp00m Aug 23 '21 at 17:13

0 Answers0