Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Ajax Object Question (Please Help)

    I have a well formed JSON object and I can access the value of an element this way:

    document.write(myObject.dataset[0].PhyFirstName);

    But what if I want to enumerate rather than epcify the element name "PhyFirstName"?

    I tried this method but it doesn't work.

    myObject.dataset[0].[3]

    or

    myObject.dataset[0][3]

    Any help GREATLY appreciated.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    An object does not have indexes like an array since it uses the name value pairs.

    In order to loop through it. you need to use the for in loop:

    Code:
    for( x in myObj){
      alert( x + ": " + myObj[x]);
    }
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much that solved my issue. By the way I have your book and it's awsem.

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Glad I could help and glas you liked my book!

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •