FormData objects can have multiple entries with the same key. The FormDatahas() method is useful checking a key exists in the object, however, when there are multiple keys with the same name it is less useful since in that case you don’t just care about the key, but also if a key and value are present.
What solutions exist today?
Today, it’s not terribly difficult to achieve this, but it does require getting all of the values as an array and then using Array methods to check if the value exists.
searchParams.has("fruit", "tomato"); // returns a boolean if there’s a matching key with the specified value
This would be useful for FormData as well. So, again where formData is a FormData object and the has() method supports a second parameter for matching the name and value in the object:
formData.has("fruit", "tomato"); // returns a boolean if there’s a matching key with the specified value
Additionally, this would help authors as there would be increased API parity between FormData and URLSearchParams.
What problem are you trying to solve?
FormData
objects can have multiple entries with the same key. TheFormData
has()
method is useful checking a key exists in the object, however, when there are multiple keys with the same name it is less useful since in that case you don’t just care about the key, but also if a key and value are present.What solutions exist today?
Today, it’s not terribly difficult to achieve this, but it does require getting all of the values as an array and then using
Array
methods to check if the value exists.For example, where formData is a
FormData
object:How would you solve it?
The
URLSearchParams
has()
method supports a second parameter for matching the value of the named param. For example, where searchParams is aURLSearchParams
object:This would be useful for
FormData
as well. So, again where formData is aFormData
object and thehas()
method supports a second parameter for matching the name and value in the object:Additionally, this would help authors as there would be increased API parity between
FormData
andURLSearchParams
.Anything else?
No response