Skip to content

Instantly share code, notes, and snippets.

@ScottKaye
Last active May 1, 2016 04:24
Show Gist options
  • Save ScottKaye/f633efe945ad38cdbfea to your computer and use it in GitHub Desktop.
Save ScottKaye/f633efe945ad38cdbfea to your computer and use it in GitHub Desktop.
Getting the querystring into an array throughout the ages
// 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