Update serializeForm.md
This commit is contained in:
@ -2,12 +2,9 @@
|
|||||||
|
|
||||||
Encode a set of form elements as a query string.
|
Encode a set of form elements as a query string.
|
||||||
|
|
||||||
1. Convert the HTML form to `FormData()`
|
Use the `FormData` constructor to convert the HTML `form` to `FormData`, `Array.from()` to convert to an array, passing a map function as the second argument.
|
||||||
2. Convert `FormData()` to `Array` using ` Array.prototype.from()`
|
Use `Array.prototype.map()` and `window.encodeURIComponent()` to encode each field's value.
|
||||||
3. Use the 2 argument `Array.from()` to pass the `map` function.
|
Use `Array.prototype.join()` with appropriate argumens to produce an appropriate query string.
|
||||||
4. On the field of each iteration, we call the map and add `window.encodeURIComponent()` to it to encode all values inside the field
|
|
||||||
5. Then on the result map call `Array.prototype.join('=')` to glue the key and value.
|
|
||||||
6. Then the result of `Array.from()` is glued together using `Array.prototype.join('&')`
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const serializeForm = form =>
|
const serializeForm = form =>
|
||||||
|
|||||||
Reference in New Issue
Block a user