Skip to main content
November 22, 2024
Question

Find index position of a string in an array

  • November 22, 2024
  • 1 reply
  • 99 views

Hi,

I’m easily able to return the value of a string in an array by it’s index position with the FIND function.

e.g. if array = [“hello”,”World”]
FIND(array,1) = “hello” 


However, i’m struggling to understand how to do the inverse - finding the index position of a string in an array by the value of the string:

e.g. if array = [“hello”,”World”]
‘STRINGFIND’(array,”hello”) = 1


I’m sure this is quite simple and I’m just missing the correct function.

Thanks!

Comments

Ian Baenziger
Lucid product team
November 22, 2024

Hi JoshJefferis!

 

At this time, we actually do not offer an out-of-the-box function for finding the index position of a string in an array. There is a very “hacky” way to do this though:

=ASARRAY(FILTER(MAP(@Haystack, x => IF(x = @Needle, x.index, NONE)), x => x != NONE))[1]

Note that this returns #ERROR! if an item isn't found. It can be wrapped in IFERROR to provide a default value like -1.

 

Also, you posted in the developer forum, so I am wondering if there are other tools at your disposal. Are you building an extension using our Extension API? If so, we may have a few other levers. If not, then the formula above is the best solution available we can think of.

 

Thanks!

Ian