Search code examples
javascriptjavascript-objects

Object key name with dash


I have to make an object with - like:

let myObject = {
  one-property: 'assignee'
}

but JavaScript does not allow this. So any trick to make this work with -? My whole backend has objects with - on keys.


Solution

  • You have to put the key in quotes

    let myObject = {
      'one-property': 'assignee'
    }