Last active
June 24, 2016 12:43
-
-
Save wildeyes/408820b5997c5ce65d169186d24ff12d to your computer and use it in GitHub Desktop.
ES 6 snippet to extract and convert the query/search string from location to a JSON object
This file contains hidden or 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
String.prototype.remove = function(str) { return this.replace(str, ''); }; | |
String.prototype.surround = function(char, char2=char) { return char + this + char2; }; | |
// String.prototype.print = function() { console.log(this); return this; }; | |
foo = location.search | |
.remove('?') | |
.split('&') | |
.map(exp => exp.split('=').map(str => str.surround('"')).join(':').surround('{', '}')) | |
// .print() | |
.join(',') | |
.surround('[', ']') | |
JSON.parse(foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment