0

I am getting the following values to put into my JSON stringify method. I will use it for AJAX. The field_name variable can vary.

value = input.val()
parent = input.parent()
userId = parent.data().userid
field_name = parent.data().field

$.ajax "/api/users/#{userId}",
  method: 'PATCH'
  contentType: 'application/json'
  dataType: 'json'
  data: JSON.stringify( {user:{field_name:value}})
  success: (data) =>

However, the keys in {user:{field_name:value}} do not express variables. Only the value of the k-v pair can express variables. How can I make the key field_name use variables to be flexible for this?

user1584575
  • 731
  • 3
  • 10
  • 20
  • 1
    possible duplicate of [Javascript variable object keys](http://stackoverflow.com/questions/12651803/javascript-variable-object-keys) – CBroe Apr 27 '14 at 17:09
  • possible duplicate of [Using a variable for a Javascript object key](http://stackoverflow.com/questions/2274242/using-a-variable-for-a-javascript-object-key) – Bergi Nov 18 '14 at 05:47

0 Answers0