题解 | #参数解析器#
参数解析器
https://www.nowcoder.com/practice/9a4cca8c0779438a8be39d45d0370597
1.先截取字符串
2.通过 URLSearchParams方法变成深度数组
3.通过 fromEntries转变成对象
var searchString = url.substring(url.indexOf('?'));
const params = new URLSearchParams(searchString)
const obj = Object.fromEntries(params)
console.log(obj)
return obj
var searchString = url.substring(url.indexOf('?')); const params = new URLSearchParams(searchString) const obj = Object.fromEntries(params) console.log(obj) return obj