JavaScript > Methods

Replace in JavaScript

How to replace a character or characters from the string in JavaScript?

In case we want to Replace a particular character or characters from the sting we can follow this approach.

        var v = "my text";
        document.write(v.replace("my", "our"));

In the above code snippet we stored “my text” string into the v variable. In the next line we have called the replace method by passing the characters to replace and characters to replace with. As a result when the above code renders on the webpage, it shows “our text”.


 Views: 4043 | Post Order: 52

Write for us

Hosting Recommendations