Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array as Object property

Status
Not open for further replies.

SarahKate31

Programmer
Feb 14, 2002
34
US
Hi everyone --
I need to use the Object constructor to create a new object with properties. I also have a multidimensional array that I would like to store as a property of the object.

sibsArr = new Array()
sibsArr[0] = new Array()
sibsArr[0][0] = "John"
sibsArr[0][1] = 26
sibsArr[1] = new Array()
sibsArr[1][0] = "Anne"
sibsArr[1][1] = 24
sibsArr[2] = new Array()
sibsArr[2][0] = "Allison"
sibsArr[2][1] = 22

var kate = new Object()
kate.age = 25
kate.siblings = sibsArr

I am getting an error when I try to reference the array like this:

kate.siblings[2]

How can I reference the elements in the array? I know I have the wrong syntax, or I am referencing it the wrong way...Can anyone help me out with this? I would appreciate it much...Let me know if I have not given enough info...

Thanks -- Kate
 
How is kate.siblings defined? In order to hold an array, it should be a Variant type. You might also have to SET kate.siblings instead of just using equal.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
your current syntax works just fine in IE and FF:

Code:
sibsArr = new Array()
sibsArr[0] = new Array()
sibsArr[0][0] = "John"
sibsArr[0][1] = 26

var kate = new Object()
kate.age = 25
kate.siblings = sibsArr

alert(kate.siblings[0])

i suspect this is not exactly how you are using it, and that you have some error elsewhere.

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
yes you are correct - this syntax does work - i had a problem elsewhere that i have now fixed...i haven't used the object constructor very often, so i assumed i had the syntax wrong...sorry!
Thank you both for your quick replies

Thanks - Kate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top