Skip to content

Instantly share code, notes, and snippets.

@ekibun
Created July 9, 2019 11:00
Show Gist options
  • Save ekibun/b5e9985f4e397ec0e30e8c6de45843a0 to your computer and use it in GitHub Desktop.
Save ekibun/b5e9985f4e397ec0e30e8c6de45843a0 to your computer and use it in GitHub Desktop.
urlquery
/*
* @Description: url query extract
* @Author: ekibun
* @Date: 2019-07-09 18:02:36
* @LastEditors: ekibun
* @LastEditTime: 2019-07-09 18:55:49
*/
const asPath = 'http://localhost:3000/products?page=1&category=5d079b&power=2'
console.log(Object.assign({}, ...(asPath.split('?')[1] || "")
.split('&').filter(item => item).map(item => item.split('='))
.map(([key, val]) => ({ [key]: val }))))
//out -> Object { page: "1", category: "5d079b", power: "2" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment