獲取url鍵值
阿新 • • 發佈:2019-01-03
String.prototype.urlkey=function (){ if(!this.split('?')[1])return; let arr=this.split('?')[1].split('&'); let arrs=[],arrAll=[] arr.forEach(item=>{ arrAll.push(item.split('=')) }) arrAll.forEach(item=>{ let obj ={} obj[item[0]]=item[1] arrs.push(obj) }); return arrs } 'https://www.baidu.com?key1=1'.urlkey()
String.prototype.urlkey=function (){ if(!this.split('?')[1])return; let arr=this.split('?')[1].split('&'); let arrs=[],arrAll=[],obj ={} arr.forEach(item=>{ arrAll.push(item.split('=')) }) arrAll.forEach(item=>{ obj[item[0]]=item[1] }); return obj } 'https://www.baidu.com?key1=1'.urlkey()