querystring.stringify({
error: 'error_status'
})
querystring is deprecated, how would I replace it with the native URLSearchParams here?
const params = new URLSearchParams({
error: 'error_status'
});
console.log(params.toString());
// error=error_status
console.log(`?${params.toString()}`);
// ?error=error_status
More information
Here's another example demonstrating how array values are handled:
let arrayParams = new URLSearchParams({
category: ['cat', 'dog']
});
arrayParams.append('tag', 'cat');
arrayParams.append('tag', 'dog');
console.log(arrayParams.toString());
// category=cat%2Cdog&tag=cat&tag=dog
console.log(decodeURIComponent('cat%2Cdog'))
// cat,dog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With