Skip to content

Instantly share code, notes, and snippets.

@jimmythai
Created March 27, 2016 05:54
Show Gist options
  • Select an option

  • Save jimmythai/ebc4830d0873c1474210 to your computer and use it in GitHub Desktop.

Select an option

Save jimmythai/ebc4830d0873c1474210 to your computer and use it in GitHub Desktop.
getQueryparameters
(($) => {
$.getQueryParameters = function(qString = location.search) {
const str = qString.replace(/(^\?)/, '');
const arr = str.split('&');
const obj = {};
for (let i = 0, len = arr.length; i < len; i++) {
arr[i] = arr[i].split('=');
obj[arr[i][0]] = arr[i][1];
}
return obj;
};
})(jQuery);
var queryParams = $.getQueryParameters('?a=1&b=10&c=100');
console.log(queryParams);
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment