Thursday, October 13, 2011

Map in Javascript



Source : http://www.coderanch.com/t/121097/HTML-JavaScript/Map-Javascript

Map in Javascript


var output = {}; 

Sort of. That just creates an empty instance of a JavaScript Object. It's identical to:

var output = new Object();   

There really isn't any implementation of Map in JavaScript.

But... JavaScript objects can be assigned properties on the fly, so an Object acts a lot like a map.

For example, after declaring your variable as shown above, you could write:

output.abc = 123;    

and now the object has a property named abc that contains the value 123.

The value can be retrieved with either of:
output.abc  
   
output['abc']  
 


No comments:

Post a Comment