
Javascript Replace Method
I’ve noticed that I always forget the syntax when needing to do a javascript replace, so I decided to write a quick post about it.
var stringToModify = "This is the string I want to modify"; var newString = stringToModify.replace("modify", "change"); alert(newString); |
the newString
variable now holds the String value “This is the string I want to change”
The javascript replace () method takes two parameters:
1) Search Value (required)
2) Replace Value (required)
It will return a new String
var.
Quick and dirty example, hopefully now I won’t need to look this up anymore. Besides, the best way to remember something is to teach something right? So I hope this post helps you out 🙂
Was this post out of sequence? I went from hello world 2 to JavaScript replace. Or was this more of a sub-post to help with your memory?
Is this post about JavaScript? or is it just a bad name?
Thank’s for the tutorials Trevor, I’m really enjoying them mate.
It was a quick post moreso for myself, it is JavaScript and not Java. I’ll eventually expand my content to include all the aspects of web development (which will include Javascript), so in the future this little one-off post won’t feel so out of place 😉
And thank YOU Nick for the comment and kind words,
all the best
Thanks Trevor!
I really enjoy your tutorials, you are so clear, you explain things very well!
Hey Durim,
Always great to hear from you, thanks for your kind words and I look forward to hearing from you in the future!