Example 1 — append for multiples
Same key twice.
JavaScript
const q = new URLSearchParams();
q.append("id", "1");
q.append("id", "2");
console.log(q.getAll("id").join(","));How It Works
- getAll returns every value.
Prefer URLSearchParams over manual string concat so encoding stays correct.
const q = new URLSearchParams();
q.set("q", "a b");
console.log(q.toString());Same key twice.
const q = new URLSearchParams();
q.append("id", "1");
q.append("id", "2");
console.log(q.getAll("id").join(","));CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful