473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1194
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Smith | last post by:
Can someone point me to an example of how to implement and access the kind of object shown below? Most of the examples if found are an object that contains one other object. I need to create an...
3
by: ABC | last post by:
I am not a javascript guru or anything so I was wondering if someone could tell me what the code below is doing. Is it creating a multidimensional array? Would it be better to create an object? ...
8
by: Thomas Mlynarczyk | last post by:
Hi! If A is an object, then "B = A;" will just assign a reference. Isn't there a simple way to create an actual copy of A and assign that to B? Greetings, Thomas
2
by: don | last post by:
My question is, do C++ array of objects hold the objects or just the pointers to the objects..... I know Java arrays only hold pointers to objects, but I seem to remember that C++ arrays hold the...
5
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: Gomaw Beoyr | last post by:
Hello Is there any explanation why Microsoft chose to implement arrays as objects allocated on the heap instead of structs allocated on the stack? For "mathematical stuff", one normally...
25
by: Jack | last post by:
Hi, Is there a general solution for the following problem: I have an array of instances of class B. Class B is publicly derived from class A. Then I have a class named Buffer that generally...
1
by: Mike Kent | last post by:
The APL 2007 conference, sponsored by ACM SIGAPL, has as its principal theme "Arrays and Objects" and, appropriately, is co-located with OOPSLA 2007, in Montreal this October. APL 2007 starts...
12
by: gnewsgroup | last post by:
I've read the msdn doc about IEnumerable. It seems to me that IEnumerable objects are essentially wrapped-up arrays. It simply gives us the foreach convenience. Is this correct?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.