Skip to content

Instantly share code, notes, and snippets.

@gungunfebrianza
Created June 24, 2025 11:00
Show Gist options
  • Save gungunfebrianza/f73c633f5d874bcd08059afa8884318d to your computer and use it in GitHub Desktop.
Save gungunfebrianza/f73c633f5d874bcd08059afa8884318d to your computer and use it in GitHub Desktop.
Query string of URL
const paramsString = "q=URLUtils.searchParams&topic=api";
const searchParams = new URLSearchParams(paramsString);
// Iterating the search parameters
for (const p of searchParams) {
console.log(p);
}
console.log(searchParams.has("topic")); // true
console.log(searchParams.has("topic", "fish")); // false
console.log(searchParams.get("topic") === "api"); // true
console.log(searchParams.getAll("topic")); // ["api"]
console.log(searchParams.get("foo") === null); // true
console.log(searchParams.append("topic", "webdev"));
console.log(searchParams.toString()); // "q=URLUtils.searchParams&topic=api&topic=webdev"
console.log(searchParams.set("topic", "More webdev"));
console.log(searchParams.toString()); // "q=URLUtils.searchParams&topic=More+webdev"
console.log(searchParams.delete("topic"));
console.log(searchParams.toString()); // "q=URLUtils.searchParams"
//https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment