Last active
May 1, 2016 04:24
-
-
Save ScottKaye/f633efe945ad38cdbfea to your computer and use it in GitHub Desktop.
Getting the querystring into an array throughout the ages
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
// ES3 | |
var getParams = function() { | |
var results = [], parts = window.location.search.slice(1).split("&"), i, len; | |
for (i = 0, len = parts.length; i < len; ++i) results.push(parts[i].split("=")); | |
return results; | |
}; | |
console.log(getParams()); | |
// ES6 | |
const getParams = () => window.location.search.slice(1).split("&").map(q => q.split("=")); | |
console.log(getParams()); | |
// ES7 stage 0 | |
let params = do { window.location.search.slice(1).split("&").map(q => q.split("=")) }; | |
console.log(params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment