JS14. 参数解析器
描述
请补全JavaScript代码,要求将字符串参数URL中的参数解析并以对象的形式返回。示例1
输入:
getParams('https://nowcoder.com/online?id=1&salas=1000')
输出:
{id:1, salas: 100}
HTML/CSS/JavaScript 解法, 执行用时: 1682ms, 内存消耗: 77772KB, 提交时间: 2022-02-10
{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n </head>\n <body>\n\n <script>\n const _getParams = (url) => {\n // 补全代码\n //getParams('https://nowcoder.com/online?id=1&salas=1000')\n //{id:1, salas: 100}\n var obj = {}\n var arr = url.split('?')[1].split('&')\n for (let i = 0;i < arr.length;i++){\n //id=1 , salas=1000\n let temp = arr[i].split('=')\n //id,1 salas,1000\n obj[temp[0]] = temp[1]\n }\n return obj\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1684ms, 内存消耗: 77812KB, 提交时间: 2022-02-09
{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n </head>\n <body>\n\n <script>\n const _getParams = (url) => {\n // 补全代码\n var obj = {};\n var arr = url.split('?')[1].split('&');\n console.log(arr);\n for (let i = 0; i < arr.length; i++) {\n let temp = arr[i].split('=');\n obj[temp[0]] = temp[1];\n }\n return obj;\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1686ms, 内存消耗: 77796KB, 提交时间: 2022-02-10
{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n </head>\n <body>\n\n <script>\n const _getParams = (url) => {\n // 补全代码\n let arr = url.split('?')[1].split('&')\n console.log(arr);\n let obj = {}\n arr.map(e=>{\n obj[e.split('=')[0]] = e.split('=')[1]\n\n })\n console.log(obj);\n return obj\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1734ms, 内存消耗: 77812KB, 提交时间: 2022-01-05
{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n </head>\n <body>\n\n <script>\n const _getParams = (url) => {\n // 补全代码\n let obj = {}\n urlArr = url.split('?')[1].split('&')\n urlArr.forEach(item => {\n itemArr = item.split('=')\n obj[itemArr[0]] = itemArr[1]\n })\n return obj\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1737ms, 内存消耗: 77796KB, 提交时间: 2022-01-22
{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n </head>\n <body>\n\n <script>\n const _getParams = (url) => {\n // 补全代码\n var obj = {}\n var param = url.split('?')[1].split(\"&\")\n for(var i=0;i<param.length;i++){ \n var temp = param[i].split('=')\n obj[temp[0]]=temp[1]\n }\n return obj\n }\n </script>\n </body>\n</html>","libs":[]}