473,387 Members | 1,536 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,387 software developers and data experts.

object array syntax

Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.

// define object with constructor function
function car(make, owner) {
this.make = make
this.owner = owner
}
// array object constructor
mycar = new Array()
mycar[0] = new car("Ford", "Ken")
mycar[1] = new car("Chevy", "Tom")
mycar[2] = new car("Dodge", "Jerry")

Jul 23 '05 #1
9 2643
On 23/06/2005 02:01, aliensite wrote:
Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.


Use an array literal:

var myObjects = [ new Object(...),
new Object(...),
new Object(...) ];

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Michael Winter wrote:
On 23/06/2005 02:01, aliensite wrote:
Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.

Use an array literal:

var myObjects = [ new Object(...),
new Object(...),
new Object(...) ];

[snip]

Mike


Use an ArrayList. It is in the java.util package.
Jul 23 '05 #3
Chris Rohr wrote:
Michael Winter wrote:
On 23/06/2005 02:01, aliensite wrote:
Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.


Use an array literal:

var myObjects = [ new Object(...),
new Object(...),
new Object(...) ];

[snip]

Mike


Use an ArrayList. It is in the java.util package.

Sorry wrong list... :-(
Jul 23 '05 #4

"aliensite" <al*******@excite.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.

// define object with constructor function
function car(make, owner) {
this.make = make
this.owner = owner
}
// array object constructor
mycar = new Array()
mycar[0] = new car("Ford", "Ken")
mycar[1] = new car("Chevy", "Tom")
mycar[2] = new car("Dodge", "Jerry")


Try:
mycar = [];
mycar.push(new car("Ford", "Ken"));
mycar.push(new car("Chevy", "Tom"));
mycar.push(new car("Dodge", "Jerry"));
Jul 23 '05 #5
aliensite wrote:
Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.

// define object with constructor function
function car(make, owner) {
this.make = make
this.owner = owner
}
// array object constructor
mycar = new Array()
num = -1;
mycar[0] = new car("Ford", "Ken")
mycar[num++] = .....
mycar[1] = new car("Chevy", "Tom")
mycar[num++] = .....
mycar[2] = new car("Dodge", "Jerry")


mycar[num++] = .....
etc..
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #6
On 23/06/2005 13:57, Randy Webb wrote:

[snip]
num = -1;
[snip]
mycar[num++] = .....


Don't you mean

num = 0;
mycar[num++] = ...;

or

num = -1;
mycar[++num] = ...;

?

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7
Michael Winter wrote:
On 23/06/2005 13:57, Randy Webb wrote:

[snip]
num = -1;

[snip]
mycar[num++] = .....

Don't you mean

num = 0;
mycar[num++] = ...;

or

num = -1;
mycar[++num] = ...;

?


Probably so. Its the effects of posting early in the morning after
working all night <sigh>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #8
aliensite wrote:
Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.

// define object with constructor function
function car(make, owner) {
this.make = make
this.owner = owner
}
// array object constructor
mycar = new Array()
mycar[0] = new car("Ford", "Ken")
mycar[1] = new car("Chevy", "Tom")
mycar[2] = new car("Dodge", "Jerry")


mycar = [
{make: "Ford", owner: "Ken"},
{make: "Chevy", owner: "Tom"},
{make: "Dodge", powner: "Jerry"}
];

http://www.crockford.com/javascript/survey.html
Jul 23 '05 #9
Thanks all!

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
6
by: Luke | last post by:
Here is my emails to Danny Goodman (but probably he is very busy so he didn't answered it). First email(simple): Subject: JavaScript Arrays " We all know the array can act like HashMap, but is...
5
by: Jon Maz | last post by:
Hi All, I'm reasonably proficient with C#, and am starting with php5. I was happy to learn of the __get and __set methods, but am encountering a problem using them to set an object property of...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
3
by: Rich | last post by:
Hello, I am converting an app from VB6 to VB.Net and have encountered the following problem. I have the following loop which retrieves objects from a collection of objects. Dim entry As...
6
by: Jake Barnes | last post by:
I was just reading this article on Ajaxian: http://ajaxian.com/archives/show-love-to-the-object-literal This is a newbie question, but what is the object literal? I thought it was like an...
47
by: Thierry Chappuis | last post by:
Hi, I'm interested in techniques used to program in an object-oriented way using the C ANSI language. I'm studying the GObject library and Laurent Deniau's OOPC framework published on his web...
19
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I access a property of an object using a string?...
4
by: Gotch | last post by:
Hi, I'm getting a very strange behaviour while running a project I've done.... Let's expose it: I've two projects. Both of them use a Form to do some Gui stuff. Other threads pack up messages...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.