// 有这样一个
// URL:http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e,
// 请写一段JS程序提取URL中的各个GET参数(参数名和参数个数不确定),
// 将其按key-value形式返回到一个json结构中,
// 如{a:'1', b:'2', c:'', d:'xxx', e:undefined}
function getJson (str) {
// 截取?后边的
str = str.split('?')[1]
let arr = str.split('&')
console.log(arr)
let jsonStr = {}
arr.forEach((item,index)=>{
let val = item.split('=')
jsonStr[val[0]] = val[1]
})
console.log(jsonStr)
}
let str = 'http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e'
getJson(str)