ReactJs String Substr


Substr() method is basically used to extract a part of string from particular position to specified characters. Here in this article, we are going to explain to use JavaScript substr() function in reactjs. You can also use our online editor to edit and run the code online.


ReactJs String Substr Method Example

You can use string function substr simply as below-

Example:

<script>
function MyFunction() {
  var myStr = "Hello World";
  var myStr1 = myStr.substr(1, 4);
  return (
    <p>Result = {myStr1}</p>
  );
}

ReactDOM.render(
  <MyFunction />,
  document.getElementById('root')
);


</script>

Try it »

If you run the above example it will produce output something like this-

ReactJs String Substr Example & Demo

Advertisements

Add Comment

📖 Read More