This is possible and simple with the URLSearchParams and FormData .
FormData is an object representation of a form for use with the fetch API. It can be built from an existing element as follows:
let form = document.forms[0]; let formData = new FormData(form);
Then follows the URLSearchParams object, which you can use to build query strings:
let search = new URLSearchParams(formData);
and now all you have to do is call the toString function on the search object:
let queryString = search.toString();
Done!
source share