1 Reply Latest reply on Oct 5, 2010 6:33 PM by SiHoop

    Searching a multidimensional array

    SiHoop Level 1

      I have 2 arrays. One is a simple array and the other is multidimensional. How do I search through the multidimensional array to find the location where an element of the simple array is stored?

       

      Thank you!

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  creationComplete="init()">
         
          <mx:Script>
              <![CDATA[
                  private var containersArray:Array=[];
                  private var containersOrderArray:Array=[];
                  private function init():void{
                      containersArray=[["a",1],["b",2],["c",3],["d",4]]
                      containersOrderArray=["s","d","e","c"]
                      for (var i:int=0;i<containersArray.length;i++){                           
                          trace("Index="+containersArray[i].indexOf(containersOrderArray[i]));
                      }
                  }
              ]]>
          </mx:Script>
      </mx:Application>

        • 1. Re: Searching a multidimensional array
          SiHoop Level 1

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  creationComplete="init()">
             
              <mx:Script>
                  <![CDATA[
                      private var containersArray:Array=[];
                      private var containersOrderArray:Array=[];
                      private function init():void{
                          containersArray=[["a",1],["b",2],["c",3],["d",4]]
                          containersOrderArray=["s","d","e","c"]
                          for (var i:int=0;i<containersArray.length;i++){       
                              for (var j:int=0;j<containersOrderArray.length;j++){       
                                  trace(j)
                                  if(containersOrderArray[i]==containersArray[j][0]){
                                      trace("Result="+containersArray[j][0]+" "+j);
                                  }
                              }   
                          }
                      }
                  ]]>
              </mx:Script>
          </mx:Application>