How to convert URL parameters to a JavaScript object?

前端 未结 30 1554
时光取名叫无心
时光取名叫无心 2020-11-22 13:57

I have a string like this:

abc=foo&def=%5Basf%5D&xyz=5

How can I convert it into a JavaScript object like this?

{
          


        
30条回答
  •  猫巷女王i
    2020-11-22 14:36

    There's a lightweight library called YouAreI.js that's tested and makes this really easy.

    YouAreI = require('YouAreI')
    uri = new YouAreI('http://user:pass@www.example.com:3000/a/b/c?d=dad&e=1&f=12.3#fragment');
    
    uri.query_get() => { d: 'dad', e: '1', f: '12.3' }
    

提交回复
热议问题