English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How can I make an array of objects, like this?:
mycars[0].maker = "Ford"
mycars[1].maker = "Pontiac"
mycars[2].maker = "Jaguar"
mycars[0].speed = 15
mycars[1].speed = 17
mycars[2].speed = 22

2006-08-06 16:41:48 · 6 answers · asked by Gregory 2 in Computers & Internet Programming & Design

6 answers

Do you want to make the Ford's speed 15,
the Pontiac's speed 17,
and the Jaguar's speed 22 ????

2006-08-06 16:48:42 · answer #1 · answered by up.tobat 5 · 0 0

var mycars = new Array();
mycars[0].maker = new Array();
mycars[1].speed = new Array();

mycars[0].maker[0] = "Ford";
mycars[0].maker[1] = "Pontiac";
mycars[0].maker[2] = "Jaguar";
mycars[1].speed[0] = 15;
mycars[1].speed[1] = 17;
mycars[1].speed[2] = 22;


that should work. i havent worked with jscript arrays in a long time.

2006-08-06 17:07:25 · answer #2 · answered by duct_tape_is_good 4 · 0 0

In Javascript, gadgets are 'associative arrays' with recognize to their homes. it incredibly is to say, each merchandise's homes are in an array listed by ability of the names of the houses, which the interpreter searches (probably making use of a version of binary search for) even as it needs to get entry to a sources. it truly is adverse to conventional compiled languages, the position the houses of an merchandise are determined by ability of its classification and won't be able to get replaced even as this methodology is operating. Javascript gadgets are talked about as 'dynamic gadgets' because they do no longer have this hardship.

2016-11-23 13:41:12 · answer #3 · answered by mengesha 4 · 0 0

like this:
var mycarMaker = new Array()
mycarMaker[0] = "Ford"
mycarMaker[1] = "Pontiac"
mycarMaker[2] = "Jaguar'
var mycarSpeed = new Array()
mycarSpeed[0] = 15
mycarSpeed[1] = 17
mycarSpeed[2] = 22

First you have to setup the array, then add items to the array. I also wouldn't use periods in the array names. Just my advice. I think javascript is case sensitive, so watch your capitalization.

2006-08-06 16:51:23 · answer #4 · answered by Bryan A 5 · 0 0

1st create a car constrcuctor to hold the car's info such as maker and speed.

create a car.
Car c = new Car()

now create an arraylist.
ArrayList List = new ArrayList();

then add the cars that u create to the array list. and thats it. an array full of car objects.

If u hav ne trouble email me a just4fun_22_2007@yahoo.com and maybe i might be able to send u the actual code.

2006-08-06 16:49:33 · answer #5 · answered by Ben D 2 · 0 0

JavaScript Arrays:

http://www.pageresource.com/jscript/jarray.htm

http://www.c-point.com/javascript_tutorial/array.htm

http://www.c-point.com/javascript_tutorial/array.htm

http://academ.hvcc.edu/~kantopet/old/javascript/index.php?page=js+arrays

2006-08-06 16:48:30 · answer #6 · answered by PureVision 2 · 0 0

fedest.com, questions and answers