objects in arrays

P

Philip WATTS

" " 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
 
L

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top