change it to
var obj = {}
$.map(inputs, function (x, y) {
obj [x.name] = $(x).val();
});
var jsonData = JSON.stringify(obj);
Why your code isn't working the way you want to?
var obj = $.map(inputs, function (x, y) {
var ret = {};
ret[x.name] = $(x).val();
return ret;
});
Simply because you are creating a new object var ret = {}; every time and setting only one value to it and then push it into an array ret[x.name] = $(x).val();. This array then you are returning return ret; which becomes part of your obj.
So, your object obj is basically an array of objects ret which has only one key x.name and value $(x).val().
By changing your code to the one I have given you will be able to get an object (which you intend to achieve) instead on an array (which you want to transform into an object).
var obj = $.extend({},json1,json2); console.log(obj);try from api.jquery.com/jquery.extend