Javascript has no associative arrays, just objects. Even JS arrays are basically just objects, just with the special thing that property names are numbers (0,1, ...).
First look at your code:
var myArray = [];
It is important to understand that myArray['a'] = 200; identical to myArray.a = 200; !
So, to start with what you want: You cannot create a javascript array and not pass any number attributes to it.
But this is probably not what you need! You probably just need a JS object, which basically matches an associative array, dictionary, or map in other languages: it maps strings to values. And this can be done easily:
var myObj = {a: 200, b: 300};
But itโs important to understand that this is a little different from what you did. myObj instance of Array will return false because myObj is not an ancestor from an array in the prototype chain.
source share