javascript - 查询参数到关联数组
问题描述
我想将查询参数设置为关联数组。
因此,例如:
http://localhost:8000/products?&size=2&type=all&nice&categories=a%20%b%20&m=true
应该:
{
size: '2',
type: 'all',
nice: undefined,
categories: ['a', 'b', 'c'],
m: 'true'
}
我的做法:
const newURI = new URL('http://localhost:8000/products?&size=2&type=all&nice&categories=a%20%b%20&m=true');
const queryParams = new URLSearchParams(newURI.search);
const associativeObj = { ...Array.from(queryParams).map(el => {
el[0]: el[1]
})
}
有人可以帮忙吗?
解决方案
推荐阅读
- cpanel - 在 GoDaddy cpanel 主机上交换主域
- c++ - 如何将字母数字和特殊字符字符串转换为字母字符串?
- xml - 具有动态多子节点的 XML 到 CSV 的通用 XSLT 转换
- c# - .Net Core 2.2 XML 序列化/反序列化
- javascript - 图表未显示在 django 管理视图中?
- c# - 如何将按钮添加到 Visual Studio 扩展的窗口?
- angular - 在非权限页面上导航时如何防止路由并显示模式?
- request - Ajax 在 Request 对象中发布 JSON 数据
- solr - Solr 存储处理
- amazon-web-services - 当对象由另一个帐户创建时,无法从 s3 存储桶上的 lambda 获取对象