javascript - How to modify JSON Stringified form information on jQuery -
hi guys taking form values on submit. firstly use
var data = json.stringify(frm.serializearray());
and result gives me
[{"name":"devicename","value":"ball"},{"name":"devicetype","value":"4949"}]
but json should
{"devicename":"ball","devicetype":4949}
and should determine whether value string or int, while modifying json
this how can do
var x = [{"name":"devicename","value":"ball"},{"name":"devicetype","value":"4949"}]; var y = {}; $.each(x,function(key,value){ y[value['name']]= value['value']; }); console.log(json.stringify(y));
note: have taken variable names x
, y
, can choose have meaningful variable names.
if want know datatype of value can use typeof
inside each
loop.
look @ fiddle link jsfiddle
Comments
Post a Comment