How to Remove all Spaces from String in React

Published on November 19, 2020 22 sec read

HIRE US 🖐
We're available to do freelance project. Take a look at our services!

Hi artisans, sometimes we need to remove all spaces from string. In this artcle, we’re going to remove all spaces from string in React.

Remove Spaces

import React from "react";

function App() {

  var myStr = " Wel come To My Note Paper ";
  var newStr = myStr.replace(/\s/g, "");

  return(
    <div>
      <p><strong>String: </strong>{myStr}</p>
      <p><strong>Without Spaces: </strong>{newStr}</p>
    </div>
  )
}

export default App;

Output

String: Wel come To My Note Paper

Without Spaces: WelcomeToMyNotePaper
That’s it. Thanks for reading. 🙂

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

Your email address will not be published. Required fields are marked *