Skip to main content
Question

Get the last Index of an Array?

  • April 25, 2018
  • 7 replies
  • 347 views

How can we use AttributeCreator which receives an array of data to only pull the last index of that array?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

david_r
Celebrity
  • 8394 replies
  • April 25, 2018

Can you give us an example of what the array looks like?


erik_jan
Contributor
Forum|alt.badge.img+22
  • Contributor
  • 2179 replies
  • April 25, 2018

If you are talking about lists in FME: The ListElementCounter will count the number of elements in a specified list. The highest index is the result of the ListElementCounter -1 (lists start at 0).


david_r
Celebrity
  • 8394 replies
  • April 25, 2018

If it's an attribute list, you can use the following functions in an AttributeCreator.

To get the last index of _list{}:

@Evaluate(@NumElements(_list{})-1)

To get the last value of _list{}:

@Value(_list{@Evaluate(@NumElements(_list{})-1)})

david_r
Celebrity
  • 8394 replies
  • April 25, 2018

Finally, you can use a ListIndexer with index set to -1 (=last element).


  • Author
  • 1 reply
  • April 25, 2018

Here's an example of what the array looks like:

capture.png

200 results contain 213 attributes of this array. I would like to get the last index of each of those arrays/nested arrays. For example, if d:ArrayOfanyType{1}.anyType{11} is the last array for d:ArrayOfanyType{1}, I want to get its value.

I hope this is clear, let me know if you need more clarification.


tim_wood
Contributor
Forum|alt.badge.img+8
  • Contributor
  • 311 replies
  • June 22, 2018

If it's an attribute list, you can use the following functions in an AttributeCreator.

To get the last index of _list{}:

@Evaluate(@NumElements(_list{})-1)

To get the last value of _list{}:

@Value(_list{@Evaluate(@NumElements(_list{})-1)})
NumElements is the key - thanks for posting that answer.  I was getting frustrated that FME refused to accept }.  I still think it should be allowed, and/or you should be able to specify _list{-1} to get the last element in the list as per ListIndexer.

 


tim_wood
Contributor
Forum|alt.badge.img+8
  • Contributor
  • 311 replies
  • June 22, 2018

Posted an idea to allow use of negative numbers to get list elements from the end of list e.g. _list{-3}:

https://knowledge.safe.com/idea/72944/use-negative-numbers-to-get-list-element-from-end.html