题解 | #获取 url 参数#
获取 url 参数
http://www.nowcoder.com/practice/a3ded747e3884a3c86d09d88d1652e10
function getUrlParam(sUrl, sKey) { let arr = sUrl.split("?")[1].split("#")[0].split("&"); const obj = {}; arr.forEach((item) => { const subObj = item.split("="); if (!Object.keys(obj).includes(subObj[0])) { obj[subObj[0]] = subObj[1]; } else { obj[subObj[0]] = [...obj[subObj[0]], ...subObj[1]]; } }); return sKey===void 0 ? obj:obj[sKey]||''