foo=1&foo=2&foo=3&blah=a&blah=b to something like foo=1,2,3&blah=a,b most optimal way foo=1,2,3&blah=a,b ? At that time he already had his own decision , and he was curious whether it could be improved in any way. function compress (data) {
var q = {}, ret = "";
data.replace (/ ([^ = &] +) = ([^ &] *) / g, function (m, key, value) {
q [key] = (q [key]? q [key] + ",": "") + value;
});
for (var key in q)
ret = (ret? ret + "&": "") + key + "=" + q [key];
return ret;
} Source: https://habr.com/ru/post/31575/
All Articles