Last active
February 1, 2017 09:19
-
-
Save mrroot5/e6fe825b5c5df8bd488d to your computer and use it in GitHub Desktop.
URL to array, convierte el query de una url a un array. Devuelve los parámetros de URL en un array.
From http://stackoverflow.com/questions/4297765/make-a-javascript-array-from-url
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
function urlToArray(url = '') { | |
var request = {}, | |
pairs, | |
i, | |
pair; | |
if (url === '') { | |
url = window.location; | |
} | |
pairs = url.substring(url.indexOf('?') + 1).split('&') | |
for (i = 0; i < pairs.length; i++) { | |
pair = pairs[i].split('='); | |
request[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); | |
} | |
return request; | |
} | |
var fullURL = urlToArray(window.location); | |
// Same result | |
var queryURL = urlToArray(window.location.search); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment