Skip to content

Instantly share code, notes, and snippets.

@xv1t
Last active November 6, 2017 18:10
Show Gist options
  • Save xv1t/c7a0c9b65a9d6cd938a1c034b436a920 to your computer and use it in GitHub Desktop.
Save xv1t/c7a0c9b65a9d6cd938a1c034b436a920 to your computer and use it in GitHub Desktop.
Parse location params after `?` and return in the object
location.href
.split('?')[1]
.split('&')
.reduce(
function(result, el){
result=result || {};
result[ el.split('=')[0] ] = el.split('=')[1];
return result
},
{});
//for example
href = 'https://yandex.ru/yandsearch?text=void&from=os&clid=1836588&lr=51';
//result
{
clid:"1836588",
from:"os",
lr:"51",
text:"void"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment