Created
December 8, 2024 10:12
-
-
Save smitroshin/c5d123ffdf7f3450764bef3663a801ec to your computer and use it in GitHub Desktop.
Encode an array of strings into query param
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Encode an array of strings into query param | |
* | |
* Format: repetitive params | |
* | |
* Example: `encodeArrayToQueryParam("param", ["a", "b", "c"])` => `"param=a¶m=b¶m=c"` | |
*/ | |
export const encodeArrayToQueryParam = (key: string, array: string[]) => | |
array.map((item) => `${encodeURIComponent(key)}=${encodeURIComponent(item)}`).join("&") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment