Last active
August 29, 2015 13:56
-
-
Save jimmynotjim/8834721 to your computer and use it in GitHub Desktop.
JS URL Param Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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