This should do the trick:
var s="value1=a&value2=&value3=b&value4=c&value5="; var tmp = s.split('&') var newS = ''; for(var i in a) { var t = a[i]; if(t[t.length - 1] !== '=') { newS += t + '&'; } } if(newS[newS.length - 1] === '&') { newS = newS.substr(0, newS.length - 1); } console.log(newS);
source share