How to create an associative array in JavaScript literal notation
<p>I understand that there are no <em>associative arrays</em> in JavaScript, only <em>objects</em>.</p>
<p>However I can create an <em>array</em> with string keys using <em>bracket notation</em> like this:</p>
<pre><code>var myArray = [];
myArray['a'] = 200;
myArray['b'] = 300;
console.log(myArray); // Prints [a: 200, b: 300]
</code></pre>
<p>So I want to do the exact same thing without using <em>bracket notation</em>:</p>
<pre><code>var myNewArray = [a: 200, b: 300]; // I am getting error - Unexpected token:
</code></pre>
<p>This does not work either:</p>
<pre><code>var myNewArray = ['a': 200, 'b': 300]; // Same error. Why can I not create?
</code></pre>