Skip to content

Instantly share code, notes, and snippets.

@szy0syz
Created July 30, 2017 07:48
Show Gist options
  • Save szy0syz/c2b907688cd850d412bc53a430f9c6b5 to your computer and use it in GitHub Desktop.
Save szy0syz/c2b907688cd850d412bc53a430f9c6b5 to your computer and use it in GitHub Desktop.
JavaScript String extension
String.prototype.queryURLParams = function () {
let obj = {},
reg = /([^?=&#]+)=([^?=&#]+)/g;
this.replace(reg, function () {
// arguments[0] === this
const key = arguments[1];
obj[key] = arguments[2];
});
return obj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment