1 2 3 4 5 6 7
function queryToString(obj) { if (!obj || !Object.keys(obj).length) return ''; let q = '?'; Object.keys(obj).forEach(key => q += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}&`); q = q.replace(/\&$/, ''); return q; }