Skip to content

Instantly share code, notes, and snippets.

@jeandcr
Created October 12, 2018 08:58
Show Gist options
  • Select an option

  • Save jeandcr/c9a54d1c6ac26168f65476d8e48e764e to your computer and use it in GitHub Desktop.

Select an option

Save jeandcr/c9a54d1c6ac26168f65476d8e48e764e to your computer and use it in GitHub Desktop.
JS Array to URLEncoded
/*
* Extend Array prototype
*/
Array.prototype.toQueryString = function(){
var out = new Array();
for(key in this){
out.push(key + '=' + encodeURIComponent(this[key]));
}
return out.join('&');
}
/*
* Standalone function
*/
function arrayToQueryString(array_in){
var out = new Array();
for(var key in array_in){
out.push(key + '=' + encodeURIComponent(array_in[key]));
}
return out.join('&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment