Skip to content

Instantly share code, notes, and snippets.

@bramburn
Created February 17, 2019 15:43
Show Gist options
  • Save bramburn/8c0cb2d7256b2b328ee8dda1b73ac226 to your computer and use it in GitHub Desktop.
Save bramburn/8c0cb2d7256b2b328ee8dda1b73ac226 to your computer and use it in GitHub Desktop.
This is a simple javascript function to convert an object to a query string
function toQueryString(obj) {
var i;
var arrayKeys = Object.keys(obj);
var returnArray = []
for(i = 0;i < arrayKeys.length;i++)
{
returnArray.push( encodeURIComponent(arrayKeys[i]) + '=' + encodeURIComponent(obj[arrayKeys[i]]));
}
return returnArray.join('&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment