469,349 Members | 1,513 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

objects in arrays

" " indicates code.

I have created a javascript object by use of a function.

object function
"function myObject(attribute1, attribute2,etc)"
{
"this.attribute1=attribute1"
"this.attribute2=attribute2"
etc
}
I wish to put the object I create into an array, so I create the array

"myObjectArray=new Array()"

Then I say that I wish to fill the aray with objects

"myObjectArray=new(myObject)"

Then I create the instances

"myObjectArray[0]=new myObject(attribute1,attribute2,etc)"
"myObjectArray[1]=new myObject(attribute1,attribute2,etc)"

This all seems to work fine until I try and establish how many objects I
have by looking at the length of my myObjectArray.

"myObjectArray.length" returns as undefined.

What am I doing wrong?

Many thanks
Phil
Jul 23 '05 #1
1 1118
Lee
Philip WATTS said:

" " indicates code.

I have created a javascript object by use of a function.

object function
"function myObject(attribute1, attribute2,etc)"
{
"this.attribute1=attribute1"
"this.attribute2=attribute2"
etc
}
I wish to put the object I create into an array, so I create the array

"myObjectArray=new Array()"

Then I say that I wish to fill the aray with objects

"myObjectArray=new(myObject)"


That's your problem. Leave that line out and it should work.
After that line, myObjectArray is no longer an array.
You don't have to say what you're going to put into an array,
and there is no way to do so.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by John Smith | last post: by
3 posts views Thread by ABC | last post: by
8 posts views Thread by Thomas Mlynarczyk | last post: by
5 posts views Thread by Gent | last post: by
21 posts views Thread by Matteo Settenvini | last post: by
25 posts views Thread by Jack | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.