Skip to content

Javascript, associative array and objects

August 10, 2012

When in javascript you define an associative array

var aa= { "one": 1, "two": 2, "three": 3 };

you are instantiating an object actually.

So these means to access the elements are equivalent:

var num= aa["two"];
var num= aa.two;

An array is still an object… but an instance of Array and elements cannot be accessed via:

var a= [ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ];
var num= a[7]; // ok, num will be 2
var num= a.7; // ERROR!!!

Enjoy.

From → Technology

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: