6 Replies Latest reply on Jul 25, 2006 4:18 PM by Newsgroup_User

    Get the key of an array?

    Level 7
      var myObject:Array ;

      myObject['name'] = "1";
      myObject['age'] = "2";
      myObject['sex'] = "3";

      for (var s in myObject) {
      trace ("myObject." + s + " = " + myObject[s]);
      }

      this doesn't work...

      i want to print out "name=1", "age=2"

      thanks...
        • 1. Re: Get the key of an array?
          Level 7
          u simply forgot 3 meaningfull chars:
          var myObject:Array = [];

          now try tracing.
          eRez

          "howachen" <howachen@gmail.com> wrote in message
          news:ea50bl$otl$1@forums.macromedia.com...
          > var myObject:Array ;
          >
          > myObject['name'] = "1";
          > myObject['age'] = "2";
          > myObject['sex'] = "3";
          >
          > for (var s in myObject) {
          > trace ("myObject." + s + " = " + myObject[s]);
          > }
          >
          > this doesn't work...
          >
          > i want to print out "name=1", "age=2"
          >
          > thanks...
          >


          • 2. Re: Get the key of an array?
            Level 7
            Then just make a change to how you trace it...

            var myObject:Array = [];
            myObject['name'] = "1";
            myObject['age'] = "2";
            myObject['sex'] = "3";
            for (var s in myObject) {
            trace ("s + " = " + myObject[s]);
            }
            --
            Jeckyl


            • 3. Re: Get the key of an array?
              Level 7
              well, what is the meaning of " = []; "

              in fact, without these characters, the array still work

              ...

              thanks as i am new to as...


              eRez wrote:
              > u simply forgot 3 meaningfull chars:
              > var myObject:Array = [];
              >
              > now try tracing.
              > eRez
              >
              > "howachen" <howachen@gmail.com> wrote in message
              > news:ea50bl$otl$1@forums.macromedia.com...
              >> var myObject:Array ;
              >>
              >> myObject['name'] = "1";
              >> myObject['age'] = "2";
              >> myObject['sex'] = "3";
              >>
              >> for (var s in myObject) {
              >> trace ("myObject." + s + " = " + myObject[s]);
              >> }
              >>
              >> this doesn't work...
              >>
              >> i want to print out "name=1", "age=2"
              >>
              >> thanks...
              >>
              >
              >
              • 4. Re: Get the key of an array?
                Level 7
                if i use the following syntax, how to do it?


                var myObject:Array = new Array();

                what is the difference?



                Jeckyl wrote:
                > Then just make a change to how you trace it...
                >
                > var myObject:Array = [];
                > myObject['name'] = "1";
                > myObject['age'] = "2";
                > myObject['sex'] = "3";
                > for (var s in myObject) {
                > trace ("s + " = " + myObject[s]);
                > }
                > --
                > Jeckyl
                >
                >
                • 5. Re: Get the key of an array?
                  Level 7
                  > if i use the following syntax, how to do it?
                  > var myObject:Array = new Array();

                  No difference

                  var myObject:Array = new Array();

                  and

                  var myObject:Array = [];

                  are identical

                  how about you actually try it , and you'd SEE that it works the same.
                  --
                  Jeckyl


                  • 6. Re: Get the key of an array?
                    Level 7
                    > well, what is the meaning of " = []; "

                    it is actually setting the variable ot have a n array in it .. wirthout
                    setting it = to something, the variable remains undefined and you cannot do
                    'myObject["name"] = "1"' etc.

                    > in fact, without these characters, the array still work

                    no .. it won't
                    --
                    Jeckyl