-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
  • 9,711
  • 9
  • 72
  • 108
  • 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
  • 43,297
  • 11
  • 81
  • 105
0

Use quotes for keys:

myObject = {"the key":["value","value2","value3"]}
James Montagne
  • 75,784
  • 13
  • 108
  • 129