# Accessing last element of array dynamically?

**URL:** <https://forum.kirupa.com/t/accessing-last-element-of-array-dynamically/238223>\
**Category:** flash\
**Created:** [September 8, 2007, 2:44pm UTC](https://forum.kirupa.com/t/accessing-last-element-of-array-dynamically/238223 "2007-09-08T14:44:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Psaldorn](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@Psaldorn](https://forum.kirupa.com/u/Psaldorn)\
**Post date:** [September 8, 2007, 2:44pm UTC](https://forum.kirupa.com/t/accessing-last-element-of-array-dynamically/238223/1 "2007-09-08T14:44:52Z")

</div>

Afternoon people,  
Well, I;ve been bashing my face against this code now and still can;t get it to work.

I have been using

```auto
myArray[myArray.length] = blah+i

```

to successfully add values to an array.

Now it’s come to retrieving the last element and… the same notation seems to give me “undefined”… which is obviously hilarious. I could use some horrendous pop-\> put back in array, keep copy for usage. But that seems frankly arse-about-face.

Tried

```auto
myArray["[myArray.length]"]
and
myArray[[myArray.length]]
and
var foo = myArray.length
trace(myArray[foo])

```

It looks like trace(this[“myArray[”+myArray.length"]") which would work if the array was publcly accessible but changing it to public just to get that to work is beyond my Occam’s razor. Must be a simpler explanation? Anyone care to enlighten me?

_sobs_
