4 Replies Latest reply on Oct 14, 2010 9:47 PM by vineet osho

    How to get item name of array from particular index.

    vineet osho Level 1

      Hello

                 Can any body explain how i get the item name of a particular array.i have an array within in array.i have to compare of the name of aary with particular key.here is the array.

       

      myArray= Array (@43b1e09)   
          [0] = Object (@42b33f9)   
              Testing_1 = Array (@4428821)   
                  [0] = Object (@43adc19)   
                      choice_id = "0"   
                      deleted = "N"   
                      downloadurl = "xyz"   
                      selected = "Y"   
                      translation = "2_486"   
                  length = 1   
              dependency = "N"   
              editable = "Y"   
              field_id = "388"   
              languagelink = "Y"   
              linked_definition_id = null   
              multivalue = "N"   
              name = "Photo"   
              otheroption = "N"   
              photovitlink = Object (@43ad0d9)   
              required = "N"   
              step = "1"   
              translation = "Photo"   
              visible = "Y"   
          [1] = Object (@43ad5d9)   
          [2] = Object (@4490089)  

       

       

      here is the structure of array i am getting from server side.i give the result array name as myArray.This array have multiple child as a object.each object having array(Testing_1 in first case).i have to get the name of that Testing_1 array and compare with my key so that i perform some operation.But i am unable to get the name of that Testing_1 array(Since it is dynamic so this name changes some times).can any body guides me how to get the name of that array.



      Thanks And Regards

         Vineet Sharma

        • 1. Re: How to get item name of array from particular index.
          BhaskerChari Level 4

          Hi Vineet Osho,

           

          You can loop through your object using for loop and can get the Array name...as shown below..

           

          for each(var obj:Object in myArray)
                          {
                           for(var str:String in obj)
                           {
                            if(obj[str] is Array)
                            {
                             var arrayName:String = str;
                            }
                           }
                          }

           

           

          Thanks,

          Bhasker

          • 2. Re: How to get item name of array from particular index.
            vineet osho Level 1

            Hi bhasker Thanks Alot This also Works for me.

             

            Needs a little favour from your side.i want to add some values at runtime in my array.for this i choose param variable which is Object type.

            I just want that how can i make my str and tempid variable dynamic.means every time a new variable added in my param object.

            hope you understand what i want to say.

             

                            var arr:Array = [];
                            var param:Object = new Object();
                            param.str = int(xml.tempImageId);
                            param.tempId = int(xml.recipeImageId);
                            arr.push(param);

            • 3. Re: How to get item name of array from particular index.
              BhaskerChari Level 4

              Hi Vineet,

               

              By what means you are trying to make str and tempid variables dynamic.

               

              I din't get you question exactly ...Will you please elaborate..??

               

              If you want to say add str and tempid first time to your param object and str1 and tempid1 to second Object, str2 and tempid2 ..etc;

               

              then you can do something like below:


              for(var i:int=0;i<10;i++)
                              {
                               param = new Object();
                               param["str"+i]    = i * 10;//pushing some random number
                               param["tempId"+i] = i * 14;//pushing some random number
                               arr.push(param);
                              }

               

               

              Check for arr variable after the loop is finished you can see your array with each object having different properties.

               

              Thanks,

              Bhasker

              1 person found this helpful
              • 4. Re: How to get item name of array from particular index.
                vineet osho Level 1

                Thanks Bhasker for your quick reply .that is what i exactly wants.you sorted out my problem once again.

                 

                thanks once again.

                 

                 

                Regards

                Vineet Osho