ReactJs String Replace
JavaScript replace() method is used to search a value in string and replace the match by specified value. Here in this tutorial, we are going to explain how you can use the replace method in ReactJs. You can also use our online editor to edit and run the code online.
ReactJs String Replace Method Example
You can use replace() function in ReactJs to replace any value in string. Here is an example of this function-
Example:
<script> function MyFunction() { var myStr = "Hello World!"; var myStr1 = myStr.replace("World", "Peter"); return ( <p>Result = {myStr1}</p> ); } ReactDOM.render( <MyFunction />, document.getElementById('root') ); </script> |
Output of above example-
Advertisements