1 /****************************2 * There is such a url:http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e,3 * Please write a JS program to extract the URL of the various get parameters (parameter name and parameter number is not determined),4 * return it to a JSON structure in key-value form,5 * such as {a: ' 1 ', B: ' 2 ', C: ', D: ' xxx ', e:undefined}. 6 ****************************/7 8 functionf2 (URL) {9 varJSON = {};Ten varREGEXP =/[\?\&] (\w{1,}) (=?) (\w{0,})/G; One A Do { -arr =regexp.exec (URL); - //Console.log (arr);//arr = [Full string, key, equal sign or ' ', value or '] the - if(arr) { - //arr[2] = = =, value = undefined - //arr[2] = = =, value = arr[3] + varKey = Arr[1]; - varValue =undefined; + A if(arr[2] = = ' = ') atValue = arr[3]; - -Json[key] =value; - } -} while(arr); - in returnJSON; - } to + //======test====== -!function () { the varurl = ' Http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e '; * console.log (f2 (URL)); $} ();
"Frontend" extracts each get parameter in the URL