let query = `q=2333&order=asc`;
const params = new URLSearchParams(query);
console.log(params.get("q"));
console.log(params.has("q"));
console.log(params.toString());
params.set("q", "123");
params.append("name", "lzx");
params.delete("q");
for (let p of params) {
console.log(p);
}
API | 作用 |
---|---|
get | 通过key获取值 |
has | 通过key判断是否存在 |
toString | 变回query |
set | 修改键值对 |
append | 追加键值对 |
delete | 根据key删除 |