Skip to content

Instantly share code, notes, and snippets.

@smitroshin
Created December 8, 2024 10:12
Show Gist options
  • Save smitroshin/c5d123ffdf7f3450764bef3663a801ec to your computer and use it in GitHub Desktop.
Save smitroshin/c5d123ffdf7f3450764bef3663a801ec to your computer and use it in GitHub Desktop.
Encode an array of strings into query param
/**
* Encode an array of strings into query param
*
* Format: repetitive params
*
* Example: `encodeArrayToQueryParam("param", ["a", "b", "c"])` => `"param=a&param=b&param=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