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") 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.
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.
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... :-(
"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"));
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
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.
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: tshad |
last post by:
I have a function:
function SalaryDisplay(me)
{
var salaryMinLabel = document.getElementById("SalaryMin");
salaryMinLabel.value = 200;
alert("after setting salaryMinLabel = " +...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I access a property of an object using a string?...
|
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...
|
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'
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
| |