const testURL = 'https://www.youzan.com?name=coder&age=20&callback=https%3A%2F%2Fyouzan.com%3Fname%3Dtest&list[]=a&list[]=b&json=%7B%22str%22%3A%22abc%22,%22num%22%3A123%7D&illegal=C%9E5%H__a100373__b4';
function parseQueryString(url) {
const obj = {}
const temp = url.split('?')[1].split('&')
const result = temp.map(item=>{
return {
key: item.split('=')[0],
value: item.split('=')[1]
}
})
obj.name = decodeURIComponent(result.find(item=>item.key === 'name').value)
obj.age = result.find(item=>item.key === 'age').value
obj.callback = decodeURIComponent(result.find(item=>item.key === 'callback').value)
obj.list = result.reduce((acc,val)=>{
return acc.concat(val.key === 'list[]'?val.value:[])
},[])
obj.json = JSON.parse(decodeURIComponent(result.find(item=>item.key === 'json').value))
}
parseQueryString(testURL)
console