SOURCE

// location.search.replace(/(^\?)|(&$)/g, "")
// url参数序列化
const url = '?courseId=我12&a=112';
const search = url.replace(/(^\?)|(&$)/g, "").split('&')
console.log(search)
// const res = search.reduce((t,v) => 
//     {
//         const [key,val] = v.split('=')
//         t[key] = decodeURIComponent(val);
//         return t;
//     }
// ,{})
// console.log(res)

// url参数反序列化
const obj = {"courseId":"我12","a":"112"};
const newObj = Object.entries(obj);
console.log(newObj);
const res = Object.entries(obj).reduce((t,v) => {
    return `${t}${v[0]}=${v[1]}&`
},Object.keys(obj).length ? "?" : "").replace(/&$/,'')


// const res = Object.entries(obj).reduce(
//     (t, v) => `${t}${v[0]}=${encodeURIComponent(v[1])}&`,
//     Object.keys(search).length ? "?" : ""
// ).replace(/&$/, "");

console.log(res);
console 命令行工具 X clear

                    
>
console