题解 | #参数解析器#
参数解析器
https://www.nowcoder.com/practice/9a4cca8c0779438a8be39d45d0370597
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <script> const _getParams = (url) => { // 补全代码 /* 请补全JavaScript代码,要求将字符串参数URL中的参数解析并以对象的形式返回。 示例1 输入: _getParams('https://nowcoder.com/online?id=1&salas=1000') 复制 输出: {id:1, salas: 100} */ let x = url.split("?") let lasturl = x[1] console.log(lasturl); let ever = lasturl.split("&") console.log(ever); // 创建对象 var obj = Object() for (each of ever) { let element = each.split("=") console.log(element[0],element[1]); obj[element[0]] = element[1] } // console.log(obj); return obj } </script> </body> </html>#split函数默认空字符分割liststrreverse#