JS URL参数和对象互相转换

技术 置顶 精帖
0 213
peng49
peng49 2024-01-23 10:08:08
 
  1. let queryString = 'a=1&b=2&c=3'

URL参数转对象

  1. //let o = Object.fromEntries(new URLSearchParams(queryString).entries())
  2. let o = Object.fromEntries(new URLSearchParams(queryString))
  3. // {a: '1', b: '2', c: '3'}

对象转URL参数

  1. let s = new URLSearchParams(o).toString()
  2. //'a=1&b=2&c=3'
回帖
登录
忘记密码?