Home > Enterprise >  How to replace querystring.stringify with URLSearchParams?
How to replace querystring.stringify with URLSearchParams?

Time:05-19

        querystring.stringify({
          error: 'error_status'
        })

'querystring' is deprecated, how would I replace it with the native URLSearchParams here?

CodePudding user response:

const params = new URLSearchParams({
  error: 'error_status'
});

console.log(params.toString());
// error=error_status

console.log(`?${params.toString()}`);
// ?error=error_status

More information at https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams

  • Related