var url = "https://xxx.com?user=tom&age=20&gender=male&score=100&score=90"
function getParams(url) {
let urlPramas = url.split("?")[1].split("&");
let obj = {};
for(let i of urlPramas){
let arr = i.split("=");
var [name,val] = arr;
if(obj[name] == undefined){
obj[name] = val
}else{
obj[name]=[].concat(val,obj[name])
}
}
return obj;
}
console.log(getParams(url))
image.png
网友评论