# Adding to an array

**URL:** <https://forum.kirupa.com/t/adding-to-an-array/14175>\
**Category:** flash\
**Created:** [February 22, 2003, 10:39pm UTC](https://forum.kirupa.com/t/adding-to-an-array/14175 "2003-02-22T22:39:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Big\_Al](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@Big\_Al](https://forum.kirupa.com/u/Big_Al)\
**Post date:** [February 22, 2003, 10:39pm UTC](https://forum.kirupa.com/t/adding-to-an-array/14175/1 "2003-02-22T22:39:59Z")

</div>

Is there a way to add a value to a preexisting array? I am by no means an actionscript expert so if you know could you try to explain it as simply as possible? Or is this function already simple and I just havent found it?

Many thanks to any who can help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2003, 11:01pm UTC](https://forum.kirupa.com/t/adding-to-an-array/14175/2 "2003-02-22T23:01:03Z")

</div>

It is called push()

Try this…

```php
myArray = ["a", "b"];
myArray.push("c");
trace(myArray);

```

The original array only has “a” and “b”, but the push adds “c”, so the output in the window should be “a,b,c” (no quotes)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2003, 11:26pm UTC](https://forum.kirupa.com/t/adding-to-an-array/14175/3 "2003-02-22T23:26:36Z")

</div>

Push adds the value at the end of the array. Unshift adds the value at the begining of the array:

```php

myArray1 = ["1", "2"];
myArray2 = ["1", "2"];
myArray1.unshift ("3");
myArray2.push ("3");
trace ("myArray1 = " + myArray1);
trace ("myArray2 = " + myArray2);

//Outputs:
// myArray1 = 3,1,2
// myArray2 = 1,2,3

```

just FYI 🙂

Cheers,  
jubs :rambo:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2003, 11:30pm UTC](https://forum.kirupa.com/t/adding-to-an-array/14175/4 "2003-02-22T23:30:26Z")

</div>

Ah, didn’t think about adding to the FRONT of the array… good catch there Jubba 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2003, 8:31pm UTC](https://forum.kirupa.com/t/adding-to-an-array/14175/5 "2003-02-23T20:31:52Z")

</div>

thank you
