Reputation: 14931
I did this
let myform = $('#myapp-product-submit-form');
let jsonFormData = JSON.stringify(myform.serializeArray());
$.post( '/coaltechtest' , jsonFormData , function(datas){
problem:
the result contains a hundred name value pairs, e.g. written out
{
'name': 'product_name',
'value': 'some cool product name'
...}
but i want
{
'product_name': 'some cool product name'
}
Upvotes: 0
Views: 24
Reputation: 1036
Map the values out.
let newArray = oldArray.map( item => { return { item.name: item.value}})
In your example oldArray is myform.serializeArray()
Upvotes: 1