I would expect the following three associative arrays to be identical:
arr1 = { "dynamic":"foo", "bar":"baz" };
key = "dynamic";
arr2 = { key:"foo", "bar":"baz" };
arr3 = {};
arr3[key] = "foo";
arr3["bar"] = "baz";
In the above examples, arr1
and arr3
are the same, but arr2
is different.
Is it possible to use dynamic keys in the declaration of a javascript associative array?