Select last value from collection

So I have a BarcodeScannerInput field in Perspective. it gets some data similar to this ["testValue1", "testValue2", "testValue3"]

I then also have an expression where I want to fetch the very last (most recent) element.

{../BarcodeScannerInput.props.data}[0] This works to get the first element however replacing [0] with [-1] does not return the last element and just remains as null

Is there any way to get the last value from a collection?

I the Ignition Expression docs and there's no mention of this that I could find.

Expression language does not allow the use of -1 like python for collection item access, you'll have to use something like

{path.to.collection}[len({path.to.collection})-1]
1 Like

This is what I ended up using! Is there any where to make suggestions for expression language to support -1 indexing? I think it would be a very nice language especially since Ignition also uses Python for scripting

If you are using my Integration Toolkit (and why wouldn't you?), you can use its relatively new qvAt() function to get negative index support.

1 Like

As mentioned in Phil's linked thread, we already have a plan to add negative indexing to known-to-be-ordered collection types. No timeline on implementation, though.