04-Apr-2023
.
Admin
Hi Dev,
Today, I am going to learn you how to use substr method in reactjs. The substr() function is used to return a part of a string. We will show how to cut part of a string in reactjs.
Substr() method is basically used to extract a part of string from particular position to specified characters.
Here I will give you simple and easy way to use substr method in reactjs. So let's see the bellow example.
Example
import React from 'react'
export default class Home extends React.Component{
render(){
var myStr = "Hello World";
var subStr = myStr.substr(1, 4);
return(
<div>
<h1>String substr Example</h1>
<p><strong>Old String : </strong>{myStr}</p>
<p><strong>New String : </strong>{subStr}</p>
</div>
);
}
}
It will help you...
#React.js