Hi,
contains - this expression in array can tell if element exists or not,(true/false)
for a simple array of number it works just as expected
Expression: contains(variables('ArrayNumber'),5)
result True
BUT
How to know if object exists in array using contains?
using contains how can I know if this arrays contains id = 2 o id = 3
After struggling to find an answer to this exact question, and nearly giving up I was able to come up with a solution that's so simple, it hurts :). Simply envelop your variable (or your array) in a "string" (thus converting it to a string) to be able to search all of its content. For your example it would be:
contains(string(variables('ArrayNumber')),'5')
In my case, I had the following output from a SharePoint choice column that I was checking if a value exists:
[{"@odata.type":"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference","Id":0,"Value":"NORTH"},{"@odata.type":"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference","Id":1,"Value":"SOUTH"}]
I used following formula to check:
contains(string(items('Apply_to_each')?['Platform'], 'NORTH')
which returned "true" as expected.
Hi, With contains function then...
contains('<collection>', '<value>')
can I pass a object to that function and validate if exist or not?
[
{
"id":1,
"nombre":"Kate"
},
{
"id":2,
"nombre":"Ana"
}
]
in a compose node I set this expression
contains(variables('ArrayFromAbove'), 'HOW TO PLACE THE OBJECT HERE LIKE ID = 2 , I DON'T KNOW WHAT TO PLACE HERE?')
if it's not possible then i think I will use more action nodes like filter or iterate as you suggests
Thanks.
You can add a Filter step with your PeopleArray as input where the expression below equals true, and the check if the length() of the array from the Filter step is >0.
contains(createArray(2,3), item()?['id'])
Pat
one naĂŻve solution, I can think of is you can convert the object into JSON and iterate over the records in json to check if the value exist in array or not
@PabloRoldan please see if this helps, I think it is a similar usecase
--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
rpersad
16
David_MA
10
Super User 2025 Season 1
Michael E. Gernaey
8
Super User 2025 Season 1