# Select last value from collection

**URL:** <https://forum.inductiveautomation.com/t/select-last-value-from-collection/105701>\
**Category:** Ignition\
**Tags:** perspective, ignition81, scripting\
**Created:** [April 29, 2025, 7:57pm UTC](https://forum.inductiveautomation.com/t/select-last-value-from-collection/105701 "2025-04-29T19:57:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spencer\_Lommel1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/spencer_lommel1/32/78679_2.png) [@Spencer\_Lommel1](https://forum.inductiveautomation.com/u/Spencer_Lommel1)\
**Post date:** [April 29, 2025, 7:57pm UTC](https://forum.inductiveautomation.com/t/select-last-value-from-collection/105701/1 "2025-04-29T19:57:12Z")

</div>

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](https://www.docs.inductiveautomation.com/docs/8.1/platform/expression-language-and-syntax#collection-and-mapping-access) and there's no mention of this that I could find.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [April 29, 2025, 8:05pm UTC](https://forum.inductiveautomation.com/t/select-last-value-from-collection/105701/2 "2025-04-29T20:05:44Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Spencer\_Lommel1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/spencer_lommel1/32/78679_2.png) [@Spencer\_Lommel1](https://forum.inductiveautomation.com/u/Spencer_Lommel1)\
**Post date:** [April 29, 2025, 8:11pm UTC](https://forum.inductiveautomation.com/t/select-last-value-from-collection/105701/3 "2025-04-29T20:11:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 29, 2025, 8:21pm UTC](https://forum.inductiveautomation.com/t/select-last-value-from-collection/105701/4 "2025-04-29T20:21:44Z")

</div>

If you are using my Integration Toolkit (and why wouldn't you?), you can use its relatively new [qvAt()](https://www.automation-pros.com/toolkit/doc/utility.html#qvat) function to get negative index support.

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934/250):
>
> That was easy. grin Automation Professionals is pleased to announce a new Production release of this Integration Toolkit. New features and changes since v2.1.0: Tag Actors tags() refactoring to return good quality even when some tag values are not good. New qvAt() function to make quality of list and dataset nested values accessible, with python-like negative index support. For Ignition v8.1: [v2.1.1.251011523](https://www.automation-pros.com/ignition/Integration%20Toolkit-2.1.1.251011523-v81.modl)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 29, 2025, 9:59pm UTC](https://forum.inductiveautomation.com/t/select-last-value-from-collection/105701/5 "2025-04-29T21:59:51Z")

</div>

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.
