-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URLSearchParams with repeated parameters #851
Comments
Can you explain what you main with code? const x = new URLSearchParams("?q=1&q=2");
console.log(x.getAll("q")); // ["1", "2"]
x.append("y", "3");
x.append("y", "4");
console.log(x.getAll("y")); // ["3", "4"]
w(x.toString()); // "q=1&q=2&y=3&y=4" |
my reading is that there's no way to create that using let params = new URLSearchParams()
params.set("q",[1,2])
params.toString() // "q=1%2C2"
params.get("q") // "1,2" |
let params = new URLSearchParams()
params.append("q", 1)
params.append("q", 2)
params.toString() // "q=1&q=2"
params.getAll("q") // [ "1", "2" ] |
Maybe we should add some examples as to how you can use it as a map and how you can use it as a multi-map. The API has been designed such that it can be used for both. If you care about map, you'd primarily use get/set; if you care about multi-map, you'd use getAll/append. delete/has are useful for both. Still curious what OP meant though. |
My bad. I did not see the |
Thanks for clarifying. Let's keep this open to track adding examples. |
What is the issue with the URL Standard?
URLs such as
foo.com/?q=1&q=2
are valid and distinct thanfoo.com/?q=1
andfoo.com/?q=2
.Most server frameworks allow
q
to be a list containing all values ([1, 2]
in the case above)However, there's no way to construct such parameters using existing
URLSearchParams
API.Is this intentionally not offered to dissuade use, or was there an RFC that said
q=1&q=2
is a wrongly formatted URL?The text was updated successfully, but these errors were encountered: