function getquery_build(query,name,value){
query = query + (query.slice(0, 1) == '?' ? '&'+name+'='+value : '?'+name+'='+value);
return encodeURI(query);
}
query = query + (query.slice(0, 1) == '?' ? '&'+name+'='+value : '?'+name+'='+value);
return encodeURI(query);
}
Usage:
query = "";
query = getquery_build(query, 'index1', 'value1');
query = getquery_build(query, 'index2', 'value2');
query = getquery_build(query, 'index3', 'value3');
query = getquery_build(query, 'index4', 'value4');
console.log(query);
query = getquery_build(query, 'index1', 'value1');
query = getquery_build(query, 'index2', 'value2');
query = getquery_build(query, 'index3', 'value3');
query = getquery_build(query, 'index4', 'value4');
console.log(query);
The output:
?index1=value1&index2=value2&index2=value2&index2=value2