Skip to content

Instantly share code, notes, and snippets.

@jimmynotjim
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmynotjim/8834721 to your computer and use it in GitHub Desktop.
Save jimmynotjim/8834721 to your computer and use it in GitHub Desktop.
JS URL Param Functions
var ArrayToURL = function(array) {
var pairs = [];
for (var key in array)
if (array.hasOwnProperty(key))
pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(array[key]));
return pairs.join('&');
};
var URLToArray = function(url) {
var request = {};
var pairs = url.substring(url.indexOf('?') + 1).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
request[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return request;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment