var str = 'https://search.jd.com/Search?keyword=夏装&pvid=a71bf8824';
function strUrlObj(str){
let strArr = str.split('?')[1].split('&'); //['keyword=夏装', 'pvid=a71bf8824']
let obj = {};
for(let i=0;i<strArr.length;i++){
let newArr = strArr[i].split('=');
obj[newArr[0]] = newArr[1];
}
return obj;
}
console.log(strUrlObj(str)); //{keyword: '夏装', pvid: 'a71bf8824'}
Analysis: What is obtained by split is an array, and then the elements of the array are converted into members of the object . Focus on understanding the content in the for loop.