- From: Nathan Knowler <notifications@github.com>
- Date: Sat, 02 Nov 2024 10:11:23 -0700
- To: whatwg/xhr <xhr@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/xhr/issues/392@github.com>
### What problem are you trying to solve? `FormData` objects can have multiple entries with the same key. [The `FormData` `has()` method](https://xhr.spec.whatwg.org/#dom-formdata-has) is useful checking a key exists in the object, however, when there are multiple keys 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 <var>formData</var> is a `FormData` object: ```javascript formData.getAll("fruit").includes("tomato"); ``` ### How would you solve it? [The `URLSearchParams` `has()` method supports a second parameter for matching the value of the named param](https://url.spec.whatwg.org/#dom-urlsearchparams-has). For example, where <var>searchParams</var> is a `URLSearchParams` object: ```javascript searchParams.has("fruit", "tomato"); // returns a boolean if there’s a match ``` This would be useful for `FormData` as well. So, again where <var>formData</var> is a `FormData` object and the `has()` method supports a second parameter for matching the _name_ and _value_ in the object: ```javascript formData.has("fruit", "tomato"); // returns a boolean if there’s a match ``` Additionally, this would help authors as there would be increased API parity between `FormData` and `URLSearchParams`. ### Anything else? _No response_ -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/xhr/issues/392 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/xhr/issues/392@github.com>
Received on Saturday, 2 November 2024 17:11:27 UTC