-2

I have a javscript object that I want to look like the following:

myObject = {the key:["value","value2","value3"]}

If I remove the space from the object such that it looks like this:

myObject = {thekey:["value","value2","value3"]}

there is no issue. How can I create an object with the above formatting?

maudulus
  • 10,627
  • 10
  • 78
  • 117
  • 4
    Can you explain what/how it didn't work when quoting they key? That works just fine. http://jsfiddle.net/66v6ocvz/ – James Montagne Mar 06 '15 at 21:01
  • @j08691 From the question " I tried using quotes around "the key" but that didn't work." – James Montagne Mar 06 '15 at 21:04
  • possible duplicate of [Valid javascript object property names](http://stackoverflow.com/questions/2940424/valid-javascript-object-property-names) – DNA Mar 06 '15 at 21:05
  • Yes my fault. I messed something up as I was writing it. Vote to close if you like – maudulus Mar 06 '15 at 21:05

2 Answers2

1

You can use quotes:

myObject = {'the key':["value","value2","value3"]}

JSFiddle

potashin
  • 44,205
  • 11
  • 83
  • 107
0

Use quotes for keys:

myObject = {"the key":["value","value2","value3"]}
James Montagne
  • 77,516
  • 14
  • 110
  • 130