0

Find index position of a value within an array

Is there a function to find the index number of an item in an array?   For example - array of [a,b,c,d] - how do I find that b is in the '1' position in the array?  I know I can do item(array,'b') to get '1' - is there a way to do the reverse?

3 replies

null
    • Sean
    • 6 yrs ago
    • Reported - view

    I know I can do item(array,'b') to get '1' 

     

    It's the other way around... item(array, index). Index must be a number. You could compare each index item until you get a match. You have some idea of what your looking for in the array or is that not the case?

    • K_Gamble
    • 6 yrs ago
    • Reported - view

    right - sorry - wrote it the wrong way.  Basically - I have a name "Tom" and I want to get the name of the Person before Tom in the array - or want everyone before Tom, etc. - so I want the index number for Tom in the array - so I can split the array at that index and then do last(), etc. on the front half.

    • Sean
    • 6 yrs ago
    • Reported - view

    You can use a while loop to find the index number and then use the slice() function.

     

    let i := 0;

    while item(array, i) != “Tom” do

    i := i + 1

    end

     

    You might have to use text(item(array,i)). I can’t test it right now.

Content aside

  • 6 yrs agoLast active
  • 3Replies
  • 2759Views