# Expression: get 3rd to last element of split(..) result

**URL:** <https://forum.inductiveautomation.com/t/expression-get-3rd-to-last-element-of-split-result/15159>\
**Category:** Ignition\
**Created:** [August 25, 2017, 12:58am UTC](https://forum.inductiveautomation.com/t/expression-get-3rd-to-last-element-of-split-result/15159 "2017-08-25T00:58:04Z")\
**Posts on this page:** 1\
**Showing post:** 12

<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:** [August 12, 2023, 6:34pm UTC](https://forum.inductiveautomation.com/t/expression-get-3rd-to-last-element-of-split-result/15159/12 "2023-08-12T18:34:48Z")

</div>

I've never been real happy with how expressions deal with common sub-expressions. That is, not happy at all. The impetus to find a solution isn't there in Perspective, because you can put such expressions ahead of a transform so they will only be executed once. (And if you have more than one, my new `asList()` expression can bundle multiple such into a single value.)

But expression tags and Vision UI bindings do not have transforms. ☹

I realized while reading this topic that I've already created a combination that can do this, and using `len()` on the result of `split()` is the perfect test case:

```auto
forEach(
	asList(
		split({path.to.some.string}, '/')
	),
	it()[len(it())-1,0]
)[0]

```

The `split()` in the center of this expression is executed once, the result dataset becomes the one element in a list to be iterated, and therefore handed to both calls to `it()` within the loop (which runs just the once) to build the output list. Take the one element of that output list as the final output.

Yielding the last element of the path, but only referencing the string property once, and only running `split()` once.

😁

---

_[View the full topic](https://forum.inductiveautomation.com/t/expression-get-3rd-to-last-element-of-split-result/15159)._
