Search code examples
azure-logic-apps

Logic Apps: selecting the first element of an array


Lets say you have an array and you want to take the first element of it. can you do this via expressions. In the below example im printing it in a teams chat.

enter image description here


Solution

  • Yep, use the first() expression ... https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#first

    Simply pass in your array and it will work ...

    first(variables('Tactic'))
    

    ... or, use the more programmatic approach ...

    variables('Tactic')[0]
    

    ... noting that array indexes start from 0.

    Tip: Press the See more button next to the Collection node in the Expression window as you've shown.