diff --git a/files/en-us/web/api/urlsearchparams/append/index.md b/files/en-us/web/api/urlsearchparams/append/index.md index a18a4b190bd85e9..98d531076d2d377 100644 --- a/files/en-us/web/api/urlsearchparams/append/index.md +++ b/files/en-us/web/api/urlsearchparams/append/index.md @@ -14,6 +14,9 @@ interface appends a specified key/value pair as a new search parameter. As shown in the example below, if the same key is appended multiple times it will appear in the parameter string multiple times for each value. +As shown in the second example below, both `name` and `value` will be automatically +encoded to be URL safe. + ## Syntax ```js-nolint @@ -34,6 +37,8 @@ None ({{jsxref("undefined")}}). ## Examples ```js +//Example: Adding the same param multiple times + let url = new URL("https://example.com?foo=1&bar=2"); let params = new URLSearchParams(url.search); @@ -42,6 +47,16 @@ params.append("foo", 4); //Query string is now: 'foo=1&bar=2&foo=4' ``` +```js +//Example: Demostrating the encoding behavior + +const params = new URLSearchParams(); + +params.append("needsEncoding$%&$#@++++++", "needsEncoding$#&*@#()+++++"); +params.toString(); +//"needsEncoding%24%25%26%24%23%40%2B%2B%2B%2B%2B%2B=needsEncoding%24%23%26*%40%23%28%29%2B%2B%2B%2B%2B" +``` + ## Specifications {{Specifications}}