JavaScript
browser
bookmarklet

JS で url query 文字列の parse ワンライナーメモ

More than 1 year has passed since last update.

Bookmarklet や DevTool console 上で使いたい時用です。

location.search

// => "?ei=nD5-WuKLBYLK0gTr_LioBw&q=atom+eslint+error+%E5%85%A8%E4%BD%93&oq=atom+eslint+error+%E5%85%A8%E4%BD%93"

const queries = location.search.substr(1).split('&').reduce((p, c) => {
const cs = c.split('=');
return Object.assign(p, { [cs[0]]: cs[1] })
}, {})

/*
=> {
"ei": "nD5-WuKLBYLK0gTr_LioBw",
"q": "atom+eslint+error+全体",
"oq": "atom+eslint+error+全体"
}
*/