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?