# Array.push Q

**URL:** <https://forum.kirupa.com/t/array-push-q/140861>\
**Category:** Uncategorized\
**Created:** [March 14, 2005, 11:48pm UTC](https://forum.kirupa.com/t/array-push-q/140861 "2005-03-14T23:48:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![abcdefg](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@abcdefg](https://forum.kirupa.com/u/abcdefg)\
**Post date:** [March 14, 2005, 11:48pm UTC](https://forum.kirupa.com/t/array-push-q/140861/1 "2005-03-14T23:48:53Z")

</div>

I have 4 buttons and an empty array. When a button is clicked,I’m adding a element to an array with array.push.

However, I want to check the array 1st to see if that element exists. If so, then don’t add it.

Here’s what I have thus far

```auto

completedElements = [];
num1.onPress = function() {
    completedElements.push("a")
    trace(completedElements.length);
    trace(completedElements);
};

```

Now I’m taking it I’d have a conditional statement to see if the element already exists. Unfortunatly I cannot just disable the button.

I searched the AS dictionary but oddly enough it doesn’t have an easy way to search an array.

And IndexOf seems to only work for a string.

Thanks :thumb:
