Last active
November 6, 2017 18:10
-
-
Save xv1t/c7a0c9b65a9d6cd938a1c034b436a920 to your computer and use it in GitHub Desktop.
Parse location params after `?` and return in the 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
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