I have an array with few items and I just want to access the last item in that array. So, after for each item in that array, what should be my next step. Thanks.
Simply MyArray.Last should do it.
Add .toString at the end if it is not a string
Ubound(MyArray) will return the index of the last item.
Hi, when I try item.last , I get all the item’s last character. But , I want the last item itself.
You are getting all the item’s last character because you are using the method inside the activity which loops the array.
Thanks a lot for the clarification. But is there a way I can access the last item inside the loop??
Yes, with the same call Susana / Florent / Clayton provided, but inside the loop. Do note that if you modify the collection in the
ForEach loop, it will break (as in - throw an exception).
What exactly are you trying to achieve? There are usually at least a couple ways to do something, and from this topic I don’t get it.
What do you need the las item in the collection inside the loop?
Usually you’d either cache it before or use after the loop. Not inside of it.
Ya I agree with @andrzej.kniola. Since you are looping through a ForEach, there is no need to know what the last item is in the loop, in my opinion. Plus, you would be storing the item every time if you use in an Assign.
However, if you still need it, you can just use my previous post as a possibility.
MyArray(0) gives you first item
MyArray(Ubound(MyArrary)) gives you last item
MyArray(MyArray.Count-1) also gives you last item
Thanks a lot