Skip to content

Instantly share code, notes, and snippets.

@cdmckay
Last active August 29, 2015 14:24
Show Gist options
  • Save cdmckay/cf4bb867ebeb630c027c to your computer and use it in GitHub Desktop.
Save cdmckay/cf4bb867ebeb630c027c to your computer and use it in GitHub Desktop.
A snippet to serialize an object in to query parameters
function serialize(object) {
return Object.keys(object).map(function (key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(object[key]);
}).join('&');
}
// Example
var params = {
username: 'cdmckay',
password: 'hunter2'
};
var serialized = serialize(params);
// serialized = "username=cdmckay&password=hunter2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment