Question:
Dynamically creating keys in javascript associative array
Typically, we initialize an array like this:
var ar = ['Hello', 'World'];
To access its values, we use:
alert(ar[0]); // Hello
However, I am looking to assign custom indexes, for example:
var ar = ['first' => 'Hello', 'second' => 'World'];
and then
alert(ar['first']);
I am having trouble figuring out how to do this assignment. Is there a way to achieve this?
Thank you!