JavaScript – short way of declaring an associative array

arraysjavascriptphp

Is there a short way of declaring an associative array like in PHP?

$myArray = array('a' => 'b'); // PHP Way

In JavaScript I'd do it this way:

var myArray = [];
myArray['a'] = 'b';

I'm not looking for JavaScript objects.

Best Solution

Declare an object like this:

var myArray = {"a": "b", "c": "d"};

... and then refer to each item like this:

var somethingElse = myArray["a"]; //Sets "somethingElse" to "b".

As @Chris and @Marc mention in the comments: in JavaScript, objects ARE associative arrays, and vice versa, they just refer to two different ways of doing the same thing. For Example...

var somethingElse = myArray["a"];
var anotherVariable = myArray.a;

... do the same thing.