jquery - convert key value pair in the payload to json object -
here json payload
"multilist": [ { "key": "my_key", "value": key }, { "key": "my_text_box", "value": "this text box" }, ]
how can dynamically convert using jquery
"multilist": [ { "my_key" : "this key" }, { "my_text_box": "this text box" }, ]
for example :
yourobj.multilist = yourobj.multilist.map(function(v) { var r = {}; r[v.key] = v.value; return r; }); if want support ie8, you'd have use shim map or use for instead of map :
for (var i=0; i<yourobj.multilist.length; i++) { var v = yourobj.multilist[i]; var r = {}; r[v.key] = v.value; yourobj.multilist[i] = r; }
Comments
Post a Comment