filterpower-automate

Filter array based on elements being a substring of another string


I have an array like this:

[
    {
        "Company-Last Name": "Alpha",
        "First Name": "One",
        "Category": "Cat"
    },
    {
        "Company-Last Name": "Beta",
        "First Name": "Two",
        "Category": "Dog"
    },
    {
        "Company-Last Name": "Gamma",
        "First Name": "Three",
        "Category": "Hamster"
    }
]

And a string that may or may not contain the Names of one of these people, for example:

This string is about Two Middle-name Beta

How do I use that to filter the first array to get:

[
    {
        "Company-Last Name": "Beta",
        "First Name": "Two",
        "Category": "Dog"
    }
]

Obviously, I can do it with a loop but that's too inefficient for the size of the actual array.


Solution

  • Try the following:

    Action: Filter Array
    From: outputs('yourArray')
    Condition Left:
     length(
      intersection(
       split(outputs('yourString'), ' '),
       createArray(item()?['Company-Last Name'], item()?['First Name'])
      )
     )
    

    Steps examples