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
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
querysyring.stringify({key: ['value1', 'value2']}) will be key=value1&key=value2, where as new URLSearchParams({key: ['value1', 'value2']}).toString() will be key=value1%2Cvalue2 where %2C is encoded ,. For array parameters you can refer this solution: stackoverflow.com/questions/38797509/…