0

I have a array with different strings (user queries) like ['..','..'..].

I also have an array with objects [{..},{..}..]

I want to filter out and based on all objects key values that match ANY of the items/strings in the array. Does not have to match all strings in the array but just one of them In the example here: filtering an array of objects based on another array in javascript However, it filters out based on a specific key.

For example, we have two objects:

   [{ 
    message: "Hi",
    unit: "Office"
    },
    { 
    message: "Bye",
    unit: "Shop"
    }]

With the string array/filter conditions:

['hi','school']

Would return the first object containing the "hi".

Example of code that filters out based on one key:

this.filteredCampaigns = this.convertedCampaigns.filter((key) => {
      filterConditions.toLowerCase().
      includes(key.description!.toString().toLowerCase())
      });

Which works, but only for one key.

How to do this?

  • Your requirement is to match the string of array with any of the object nodes in the second array OR you want to check for any particular node in array of objects? – Diwakar Singh Mar 27 '21 at 16:58
  • You want `all` objects that matches `any` of the string. What does it mean. Elaborate please – DecPK Mar 27 '21 at 16:58
  • Maybe I was unclear. With "any" I mean all key values in the object, not a single key so the filter should take a look on all key values, With "matches any of the strings" I mean that any single string of the array that matches any key value of the object would be true, and not the combination of all strings in the array. – SharePointBeginner Mar 27 '21 at 17:10

0 Answers0