Skip to content

Instantly share code, notes, and snippets.

@chodorowicz
Created June 14, 2016 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chodorowicz/e94a63db1e360cb92ec05cf15078fa64 to your computer and use it in GitHub Desktop.
Save chodorowicz/e94a63db1e360cb92ec05cf15078fa64 to your computer and use it in GitHub Desktop.
jQuery serialize form using serializeArray
function serializeForm($form) {
return $form.serializeArray().reduce( (result, input) => {
result[input.name] = input.value;
return result;
}, {}
);
}
@marioizquierdo
Copy link

Sure. But if multiple inputs have the same name, this will only return the first one of them. Which maybe fine in your case. If you need a more complete solution, check out https://github.com/marioizquierdo/jquery.serializeJSON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment