Another common String
object task is replacing one substring with another. To replace a word or phrase in a string, you use the replace()
method. The following code replaces the text "<username>"
with the value of the variable username
:
var username = "Brad";
var output = "<username> please enter your password: ";
output.replace("<username>", username);