Skip to main content
Question

Get the last Index of an Array?


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

7 replies

david_r
Evangelist
  • April 25, 2018

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


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • 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
Evangelist
  • 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
Evangelist
  • April 25, 2018

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


  • Author
  • 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
  • June 22, 2018
david_r wrote:

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
  • 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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings