# \[AS2\] Comparing arrays - see if an item exists in another array

**URL:** <https://forum.kirupa.com/t/as2-comparing-arrays-see-if-an-item-exists-in-another-array/280612>\
**Category:** flash\
**Created:** [January 29, 2009, 1:31pm UTC](https://forum.kirupa.com/t/as2-comparing-arrays-see-if-an-item-exists-in-another-array/280612 "2009-01-29T13:31:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ConceptUK2009](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@ConceptUK2009](https://forum.kirupa.com/u/ConceptUK2009)\
**Post date:** [January 29, 2009, 1:31pm UTC](https://forum.kirupa.com/t/as2-comparing-arrays-see-if-an-item-exists-in-another-array/280612/1 "2009-01-29T13:31:00Z")

</div>

Hi,

I am having a fair amount of trouble with arrays. I have some script which grabs stuff from an xml file. The stuff grabbed from the xml is in a loop to create an automatic menu. This is all fine and dandy. Say there are 9 items in the xml file, I get 9 menu items with their unique id’s.

What I want to do is define an array for comparison against the info taken from the xml file. Say in the xml file I have nodes set up for Apple, Pear, Banana and Orange. With my current script I would get a menu with these items on it. What I need to do is be able to specify the items I want to appear on the menu. For this example I would want Apple and Banana only.

I have experimented with if statements, and it takes too much code to accomplish what I want I am sure there is a more compact way. My idea is to set an array with the items I want in it, then when the information is taken from the xml file, I need the script to do the function of creating menu items only with the items I have specified in the array. Below I have added the code, which has been modified from Kirupa’s own squirrel finder tutorial. I need the code to be as reusable as possible, ie only the array would need to change. In my code the variable featureType would contain the information I need to compare against.

Any help is much appreciated. I have googles arrays and have read information on arrays from a book I own, but cannot quite get it.

```auto
//set limits on the features that need to display
// define array
var featureLimits:Array = ["Apple", "Banana"];

//filter function to get correct info from xml file
//and send variables to relevant areas
function createFeaturesMenu(){
    var features = features_xml.firstChild.childNodes;
    for(var i:Number = 0; i < features.length; i++){
        var featureType = features*.attributes.type;
        trace(featureType);
        var featureLabel = features*.firstChild;
        var featureDescription = features*.childNodes[1];
        var feature_mc = menu_mc.attachMovie("menu_item","item" + item_count, item_count);
        //count menu_items and increase distance between menu_items
        feature_mc._y = item_count * item_spacing;
        item_count++;
        //set text format on menu_item text fields
        feature_mc.feature_txt.embedFonts = true;
        feature_mc.feature_txt.antiAliasType = "advanced";
        feature_mc.feature_txt.setNewTextFormat(menuFormat);
        //pass variables out to text areas
        feature_mc.feature_txt.text = "> " + featureLabel.firstChild.nodeValue;
        feature_mc.feature_btn.featureText = featureDescription.firstChild.nodeValue;
        feature_mc.feature_btn.featureLogo = featureType;
        feature_mc.feature_btn.onRelease = DisplayInfo;
    }
};

```
