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.

<script>
        var v = "my text";
        document.write(v.replace("my", "our"));
</script>

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”.

OUTPUT

 Views: 4136 | Post Order: 52



Write for us






Hosting Recommendations