Created
July 9, 2019 11:00
-
-
Save ekibun/b5e9985f4e397ec0e30e8c6de45843a0 to your computer and use it in GitHub Desktop.
urlquery
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
/* | |
* @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