user3109009 user3109009 - 4 months ago 37
Javascript Question

Javascript replace all "%20" with a space

Is there a way to replace every "%20" with a space using JavaScript. I know how to replace a single "%20" with a space but how do I replace all of them?

var str = "Passwords%20do%20not%20match";
var replaced = str.replace("%20", " "); // "Passwords do%20not%20match"


Check this out: Replacing all occurrences of a string in javascript?

Short answer:

str.replace(/%20/g, " ");

EDIT: In this case you could also do the following: