Initializing Associative Arrays?

M

Magoo

I am writing an app that has some lookup data in a mysql DB. I want to
use javascript to fill in the default values for 5 or 6 fields when the
user selects from a list.

I want to initialize an associative array with the default values. In
perl I'd do this:

my $inventory = )
{ ITEM => 1, NAME => 'Widget', COST => 3.99},
{ ITEM => 2, NAME => 'Dohicky', COST => 5.95{
);

How do I do that in javascript?

var inventory = new Array (
new Array ( ???????? ),
new Array ( ???????? )
);
 
L

Lee

Magoo said:
I am writing an app that has some lookup data in a mysql DB. I want to
use javascript to fill in the default values for 5 or 6 fields when the
user selects from a list.

I want to initialize an associative array with the default values. In
perl I'd do this:

my $inventory = )
{ ITEM => 1, NAME => 'Widget', COST => 3.99},
{ ITEM => 2, NAME => 'Dohicky', COST => 5.95{
);

How do I do that in javascript?

var inventory = new Array (
new Array ( ???????? ),
new Array ( ???????? )
);

You use an Object as an associative array:

var inventory = new Array (
{name:"widget", cost:3.99 },
{name:"Dohicky", cost:5.95 }
);
alert(inventory[0]["name"]);
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top