const queryString = Object.keys(params).map(key => {
encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
}).join('&');
const obj = {foo: "hi there", bar: "100%" };
const params = new URLSearchParams(obj).toString();
queryBuilder = function(obj, prefix) {
var str = [],
p;
for (p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p,
v = obj[p];
str.push((v !== null && typeof v === "object") ?
serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}
console.log(
serialize({
foo: "hi there",
bar: {
blah: 123,
quux: [1, 2, 3]
}
})
);