I'm serializing a form as follows (inspired by this answer):
function formToArray(jQueryObj){
var result = {};
var arr = jQueryObj.serializeArray();
$.each(arr, function(){
result[this.name] = this.value;
});
return result;
}
This returns an object such as {"input1_name":"value1", "input2_name": "42"}
. However, some of the inputs are numeric, and I want them to return numbers instead of strings. So my desired output is {"input1_name":"value1", "input2_name": 42}
, the number not in quotes.
How can I achieve this with jQuery/JavaScript?
Thanks,