Skip to content

Instantly share code, notes, and snippets.

@domosedov
Created June 7, 2020 12:44
Show Gist options
  • Save domosedov/692287f1aaa766ca32d4e5e346666dc8 to your computer and use it in GitHub Desktop.
Save domosedov/692287f1aaa766ca32d4e5e346666dc8 to your computer and use it in GitHub Desktop.
Convert FormData to Query String
function handleSubmit(event) {
event.preventDefault();
const formData = new FormData(event.target);
const data = [...formData.entries()];
const asString = data
.map(x => `${encodeURIComponent(x[0])}=${encodeURIComponent(x[1])}`)
.join('&');
console.log(asString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment