📅  最后修改于: 2022-03-11 14:48:30.978000             🧑  作者: Mango
type mapping = {
[key: string]: string
}
function url_to_object(url: string): mapping {
const data: {[key: string]: any} = {}
url
.replace(/\/\?/, '')
.split('&')
.map(x => x.split('='))
.forEach(x => {
data[x[0]] = x[1]
})
return data;
}
url_to_object('id=4&second=3') // {id: 4, second: 3}