Skip navigation

What is associative array?
Its an array who’s index is a string instead of a number.

What do you mean by it?

// Array
var myArr = Array(3);
myArr[0] = 34;
myArr[1] =  'rajakvk'; // legal store all types in a single array. ;-)
myArr[2]= 25.5;

//Associative array
var myArr = Array(3);
myArr['age'] = 34;
myArr['what is his name'] =  'rajakvk';
myArr["what is his father's name"] = 'kvk';
myArr['his average']= 25.5;

Yes. You can use string, with space too. Even you get to know father’s name !!

Its legal in JavaScript. Now you can understand the flexibility of JavaScript.

But

alert(myArr[1]);  //undefined

That reminds again, great power comes with great responsibility.
Advertisements

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: