Sometimes, we want to replace all “%20” with a space with JavaScript.
In this article, we’ll look at how to replace all “%20” with a space with JavaScript.
How to replace all “%20” with a space with JavaScript?
To replace all “%20” with a space with JavaScript, we call the decodeURI
function.
For instance, we write
const s = decodeURI(str);
to call decodeURI
with str
to return a string with all '%20'
substrings removed from it.
Conclusion
To replace all “%20” with a space with JavaScript, we call the decodeURI
function.