LoginSignup
1
1

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-02-10

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+全体"
}
*/
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1