My Book

split--将字符串转为数组

    let url ="http://www.taoba.com/index.php?key0=0&key1=1&key2=2";
    let obj = parseQueryString(url);
    console.log(obj.key2);
    function parseQueryString(url){
        let str = url.split("?")[1];
        let arr = str.split("&");
        let result = {};
        for(let i=0;i<arr.length;i++){
            let obj = arr[i].split("=");
            result[obj[0]] = obj[1];
        }
        return result;
    }