Finding a value within an array
Posted: Sunday 5th March 2023 9:40am
If I had an array with various integer values and wanted to find what index value contains a given search value, is there a command to do that, or do I simply have to write a little search function?
For example. If I had the following array:
and I was looking for 3, I would want a function to return the value 4.
Or, if I was looking for 6, I'd want it to return the value 1.
Is there a built in function that can do this, or do I have to write a simple FOR EACH loop and do it manually. I know in some languages like PHP they have such functions array_search($needle, $haystack).
For example. If I had the following array:
Dim ar As Integer[]
ar=array(5,6,4,7,3,8,2,9,1,0)
and I was looking for 3, I would want a function to return the value 4.
Or, if I was looking for 6, I'd want it to return the value 1.
Is there a built in function that can do this, or do I have to write a simple FOR EACH loop and do it manually. I know in some languages like PHP they have such functions array_search($needle, $haystack).