我想使查询参数成为一个关联数组。
因此,例如:
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');
const queryParams = new URLSearchParams(newURI.search);
const associativeObj = { ...Array.from(queryParams).map(el => {
el[0]: el[1]
})
}
有人可以帮忙吗?
URLSearchParams.forEach()