How to Remove all Spaces from String in React

Published on November 19, 2020 22 sec read

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, "");

      <p><strong>String: </strong>{myStr}</p>
      <p><strong>Without Spaces: </strong>{newStr}</p>

export default App;


String: Wel come To My Note Paper

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

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.

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