Category Archives: ReactJs

ReactJs get string length


ReactJs get string length– We can use string length method to get the length of any string in reactjs. Here in this tutorial, we are going to explain how you can get the string length using native JavaScript length method. You can also use our line editor to edit and run the code online.


ReactJs get string Length Method Example

You can get length of any string in reactJs simply as below-

Example:


Try it »

Output of above example-

Reactjs get string length JavaScript Example

ReactJs Redirect to URL


JavaScript navigator location.href property is used to redirect to specified url. Here in this tutorial, we are going to explain how you can use loccation.href in ReactJs. You can also use our online editor to edit and run the code online.


ReactJs Redirect to URL Method Example

You can redirect to specified url simply as below-

Example:


Try it »

ReactJs Scroll To Top


We can use navigator location property to scroll to top of the page. Here in this tutorial, we are going to explain how you can use the navigator location property in ReactJs. You can also use our online editor to edit and run the code online.


ReactJs Scroll To Top Method Example

You can create button to “Go to top” simply as below-

Example:


Try it »

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:


Try it »

Output of above example-

ReactJs String Replace Example

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:


Try it »

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

ReactJs String Substr Example & Demo

ReactJS Trim String


We can use JavaScript trim method to remove spaces from both end of the string. Here in this tutorial, we are going to explain how to use trim method in reactJs. You can also use our online editor to edit and run the code online.


ReactJS Trim String Method JavaScript Example

You can use JavaScript trim() function in ReactJs Simply as below-

Example:


Try it »

In the above example you can see string “Hellow World” contains blank space at the both end. If you check the length with space it will return 13, if you trim this string it will return length 11.

Output of above example-

ReactJs trim String Example

ReactJs Get Current Date Time


We can use native Javascript date function to get the current and time in ReactJs. Here in this tutorial, we are going to explain how you can use javascript dete function to get the current date and time. You can also use our online editor to edit and run the code online.


ReactJs Get Current Date Time JavaScript Example

You can get the current date time in YYYY-MM-DD H:i:s Format simply as below-

Example:


Try it »

Output of above example-

ReactJs Get Current Date Time

ReactJs get Current Url


We can use native javascript window.location.href property to get the current url anywhere like component in react js. Here in this tutorial, we are going to explain how you can use this method to get the current url in reactjs. You can also use our online editor to edit and run the code online.


ReactJs get Current Url JavaScript Example

You can use window.location.href in react js simply as below-

Example:


Try it »

Output of above example-

ReactJs get Current Url JavaScript Example

ReactJs Remove Duplicates from Array


We can remove the duplicate values from an array in reactjs filter.


ReactJs Remove Duplicates from Array Example

You can use the simplest way to remove duplicate items from an Array simply as below-

Example:

var myArray = [100,80, 70, 80, 90,100, 71, 80];
const finalArray = [];
const finalArray = myArray.filter(function(elem, pos) {
    return myArray.indexOf(elem) == pos;
}); 
// will return  [100, 80, 70, 90, 71];

On the same way we can remove any duplicate value from array.

Output of above example will be array of unique values- [100, 80, 70, 90, 71];