PDA

View Full Version : Ajax Object Question (Please Help)



jetrica
Aug 2nd, 2007, 07:48 PM
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.:thumbsup:

A1ien51
Aug 2nd, 2007, 08:18 PM
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:



for( x in myObj){
alert( x + ": " + myObj[x]);
}


Eric

jetrica
Aug 2nd, 2007, 09:17 PM
Thank you so much that solved my issue. By the way I have your book and it's awsem.

A1ien51
Aug 3rd, 2007, 05:15 PM
Glad I could help and glas you liked my book!

Eric