SOURCE

let str = "https://juejin.cn?name=zhangsan&age=18&id=123";

function calculateQuery(url) {
    const result = {};
    const arr = str.match(/(\?|\&)(\w*)=(\w*)/g)
    arr.forEach(item => {
        const [,,key, value] = item.match(/(\?|\&)(\w*)=(\w*)/)
        result[key] = value;
    })
    return result;
}

console.log(calculateQuery(str))
console 命令行工具 X clear

                    
>
console