Skip to content

Instantly share code, notes, and snippets.

@faxemaxee
Created October 12, 2018 13:32
Show Gist options
  • Save faxemaxee/5e8d66213b416c44e8145f3090455c21 to your computer and use it in GitHub Desktop.
Save faxemaxee/5e8d66213b416c44e8145f3090455c21 to your computer and use it in GitHub Desktop.
function getFormData($form) {
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function (n, i) {
if (n["name"].indexOf('[]') >= 0) {
var key = n["name"].slice(0, -2);
if (!indexed_array[key]) indexed_array[key] = [];
indexed_array[key].push(n['value']);
// } else {
indexed_array[n['name']] = n['value'];
}
});
return indexed_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment