Get an array element at a specific index

Options
I'm not sure how to retrieve the element of an array that is at a specific index.

For example, in…
["one", "two", "three", "four", "five"]… I would like to get the element at the index `2`, in this case…
"three"
How would it go about doing it in Xano? I don't see a relevant manipulation in the Array menu. I also don't see the right filter to get it with a variable.

Comments

  • Georges Duverger
    Georges Duverger Trusted Xano Expert
    Options
    I got optimistic when I saw the `range` filter but it seems that it's just creating a range regardless of the object it's applied to, which makes sense. I might be reading it incorrectly, but from the doc, it seems that it's returning elements between two indices. 🤷‍♂️
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    You can spell it out with dot notation or use the get filter.

    so if you had the following:

    var item = ["one","two","three","four","five"];

    Then you would access three by doing 

    var:item.2

    or

    var:item|get(2)
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    You are right the range filter description is misleading. We will fix that. It currently gives you an array of numbers between a start and stop.
  • Georges Duverger
    Georges Duverger Trusted Xano Expert
    Options
     Excellent! I was able to make it work with the `get` filter. For some reason, I thought it was meant only for dictionaries. But it's on me, the UI is clear now that I'm looking back it it. All good, as usual.