[thelist] Q on assoc arrays

Ken Schaefer ken at adOpenStatic.com
Mon Dec 15 00:25:00 CST 2003


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "jsWalter" <jsWalter at torres.ws>
Subject: RE: [thelist] Q on assoc arrays

: <snip>
:
: > The solution to your problem is to use "object literal" syntax,
: > which looks like this:
: >
: > var myArray = {
: >    ac: 'Ascension Island',
: >    ad: 'Andorra',
: >    ae: 'United Arab Emirates',
: >    af: 'Afghanistan'
: > };
: >
: > That will create an object called "myArray" prepopulated with all of
: > your data.
:
: That's it! You took it one level back *up* from the example on
:      http://www.crockford.com/javascript/survey.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Not at all - the example is listed on the page cited, under the heading
"objects".

Creating the object
var myObject = {name: "Jack B. Nimble", 'goto': 'Jail', grade: 'A', level:
3};


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: > var country = myArray['ac'];
: >
: > or
: >
: > var country = myArray.ac;
:
: Yes, this is *exactly* the  "side effect" I'm looking for!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Refering to the object:
myObject.nickname = 'Jackie the Bee';

Cheers
Ken



More information about the thelist mailing list