Skip to content

Instantly share code, notes, and snippets.

@sh1mmer
Created April 3, 2010 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sh1mmer/354941 to your computer and use it in GitHub Desktop.
Save sh1mmer/354941 to your computer and use it in GitHub Desktop.
var data = "";
for (p in parameterMap) {
data += p + "=" + encodeURIComponent(parameterMap[p]) + "&";
}
//kill the trailing &
data = data.slice(0,-1);
@Gozala
Copy link

Gozala commented Apr 4, 2010

// assuming you have es5 Object.keys will be slower though

function encodeParams(params) {
    return Object.keys(params).map(function(key) {
        return encodeURIComponent(params[key]);
    }).join("&");
}

@ktiedt
Copy link

ktiedt commented Apr 4, 2010

since you are already looping over the object...

var data = [];
for (p in parameterMap) {
data.push(p + '=' + encodeURIComponent(parameterMap[p]));
}
//kill the trailing &
data = data.join('&');

@sh1mmer
Copy link
Author

sh1mmer commented Apr 4, 2010

Whoops. Already revved it over here: https://gist.github.com/354949/76df91273a5be7370f0df004f934dad95a6d3e23

Thanks for the suggestions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment