Encountering a perplexing issue, as the JavaScript code provided below generates an Unexpected Token error in Chrome:
var somearray = ["foo","bar"];
var someassoc = {somearray[0]:somearray[1]};
The specific error message displayed is:
Uncaught SyntaxError: Unexpected token [
One would anticipate that the code should simply create an object where somearray[0]
serves as the key and somearray[1]
acts as the corresponding value.
Hence, why does this error occur? Typically, an Unexpected Token
signifies misplacement of brackets or similar issues, but such mistakes are not evident in this scenario.