3 Replies Latest reply on Oct 29, 2009 4:04 AM by flexprad09

    Existence of an entry in Associative array

    Shirker1

      Hi:

       

      How do I test for existence of an individual entry in an array defined as   var a:Object = new Object();

       

      if (a["something"] exists ) something like this

       

      Thanks

        • 1. Re: Existence of an entry in Associative array
          flexprad09

          You can either use DOT operator "."

          or Bracket ["YOUR INDEX"]

           

          Check this link

           

          http://livedocs.adobe.com/flex/3/html/help.html?content=10_Lists_of_data_4.html

           

          If this posts answers your question mark it accordingly.

           

          Cheers,

          PRad

          • 2. Re: Existence of an entry in Associative array
            Shirker1 Level 1

            Thanks for your reply.

             

            The actual answer is as this:

             

            var a:Array = new Array();

             

            test if entry is in array by  the following enchantment|:  

            if ( key in b)

            if you do a[key] you get a null object reference.

             

            Cheers

            • 3. Re: Existence of an entry in Associative array
              flexprad09 Level 2

              <mx:Script>
                      <![CDATA[
                          import mx.controls.Alert;
                              private var masterTaskList:Array = new Array();
                             
                              private function init():void{
                                  masterTaskList["Monday"] = ["wash dishes", "take out trash"];
                                  masterTaskList["Tuesday"] = ["wash dishes", "pay bills"];
                                  masterTaskList["Wednesday"] = ["wash dishes", "dentist", "wash dog"];
                                  masterTaskList["Thursday"] = ["wash dishes"];
                                  masterTaskList["Friday"] = ["wash dishes", "clean house"];
                                  masterTaskList["Saturday"] = ["wash dishes", "wash car", "pay rent"];
                                  masterTaskList["Sunday"] = ["mow lawn", "fix chair"];
                                  if(masterTaskList["Monday"])
                                  Alert.show(masterTaskList["Monday"].toString());
                                  if("Monday" in masterTaskList)
                                  Alert.show(masterTaskList["Monday"].toString());
                             
                              }

               

                      ]]>
                  </mx:Script>

               

              Both are same.

               

              I display both Alerts.

               

              Cheers,

               

              Prad.