摘要:
将url后的参数键值对转换成JSON数组格式let url = "http://www.ncyteng.com?names=zhuang&a...
将url后的参数键值对转换成JSON数组格式
let url = "http://www.ncyteng.com?names=zhuang&sex=man&age=18";let querys = url.substring(url.indexOf('?') + 1).split('&').map((query) => query.split('=')).reduce((params, pairs) => (params[pairs[0]] = pairs[1] || '', params), {});console.log(querys);//{age:"18",names:"zhuang",sex:"man"}