javascript associative array syntax

 

 

 

 

An associative array is the way I would imagine it should be done, but the following seems a little long winded and Im hoping someone has a better way to do it or shorthand of what I have belowYou can use JavaScript object literal syntax In JavaScript, you cant use array literal syntax or the array constructor to initialize an array with elements having stringYou may have heard conflicting information about associative arrays in JavaScript. JavaScript arrays are used to store multiple values Using an array literal is the easiest way to create a JavaScript Array. Syntax: varBrowse other questions tagged java associative-array or ask your own question. Im creating/writing the array on the server side from Perl, but I keep getting a javascript error message saying "arrayName.key1 has no properties."As a side note, you dont need to use Arrays when you want an " associative array" (which is just another word for "map"). On this page I explain how JavaScript objects are also associative arrays (hashes). Using these you can associate a key string with a value string, which can be very useful sometimes. Suppose you have a mouseover / click image swap script. Associative arrays as objects. Notice that the object/property syntax is just that - some alternative syntax for accessing an associative array. It is quite a thought that all of JavaScripts object- oriented features come from the associative array plus one additional operator. You may be finding conflicting information about associative arrays in JavaScript. Well, the answer is quite simple and then things start to get a little odd.The good news is, the answer is simple: associative arrays are not supported in JavaScript. Last Modified: 2009-12-16. Javascript associative array syntax problem.