1 Reply Latest reply on Jun 13, 2006 7:56 AM by ur_dtrain

    ArrayCollection and contains

    ekokurtz
      I have created an array of multiple objects, and want to be able to search in the array as I loop over rows in a datagrid to determine whether to add an entry to the array (if not present). At first I tried using indexOf, but that doesn't work if the array has multiple named values. I switched to adding the array to an arraycollection and am trying to use arraycollection.contains...

      Not having any luck, so am curious to see syntax for checking on the existence of a value from the array in the array collection. Surely it has to be easier than I am making it - here is my latest attempt:


      function testArray() {
      var test:Array = [{Classname:"class 10",data:1},{Classname:"class 11",data:2}];
      var testAc:ArrayCollection = new ArrayCollection(test);

      for (var i=0;i<test.length;i++) {
      Alert.show(testAc.contains('class 10').toString());
      }

      }

      Hopefully someone has already done this or something similar

      Ethan
        • 1. Re: ArrayCollection and contains
          ur_dtrain Level 1
          Ethan,
          If you are going to this much trouble, you might as well simply capture the Classname property and push it into a seperate array, then go back to using indexOf.

          var nameArray:Array = new Array();

          for (var index:int=0 ; index<test.length ;index++){
          nameArray.push(test[index].Classname);
          }
          var isItHere:int = nameArray.indexOf('Class 1');