ReactJs Remove all spaces from string


There are many ways to remove white spaces from a string. We can use use string replace method to remove all spaces from string in Reactjs. Here in this article we are going to explain how you can use native JavaScript method to replace all spaces from string. You can also use our online editor to edit and run the code online.


ReactJs Remove all spaces from string JavaScript Example

Here is an example to remove spaces using replace function-

Example:

<div id="root">
</div>
<script>
function MyFunction() {
  var myStr = 'T U T O R I A L S P L A N E';
  var result = myStr.replace(/\s/g, "");
  return (
    <p>{result}</p>
  );
}

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

Try it »

Output of above example-

ReactJs Remove all spaces from string

Advertisements

Add Comment

📖 Read More