How can I correct the following code?
JavaScript has associative arrays.
Here is a working snippet.
They are simply called objects.