Skip to content

Instantly share code, notes, and snippets.

@blanks88
Created July 7, 2023 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blanks88/e088d7857e30545cb17f2849caa0fe9f to your computer and use it in GitHub Desktop.
Save blanks88/e088d7857e30545cb17f2849caa0fe9f to your computer and use it in GitHub Desktop.
Typescript: Function to convert any object into querystring
  protected ToQueryString(q: any): string {
    const params = new URLSearchParams(q);
    const keysForDel: any[] = [];

    params.forEach((value, key) => {
      if (value == '') {
        keysForDel.push(key);
      }
    });

    keysForDel.forEach(key => {
      params.delete(key);
    });

    return decodeURI(params.toString());
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment