How to remove spaces from string in ReactJS

Today, I am explaining you, if you are working in ReactJS so how to remove all spaces from string in ReactJS. in some custom requirement we need to remove spaces from string so we can use it. here, I will use string replace function for remove spaces from string.

Example :

import React from "react";
function Unity() {

  var stringData = "Hi, Wel come to Web Developers India website's ReactJS post";
  var newStringData = stringData.replace(/\s/g, "");
  return (<><div id="wrapper" className="full-screen" style={{ background: "#ccc"}} ><div><p  style={{ padding: "5px" }}><strong>Old String With Spaces: </strong>{stringData}</p><p style={{ padding: "5px" }}><strong>New String Without Spaces: </strong>{newStringData}</p></div></div> </>

  );
}

export default Unity;

Output :

Leave a Reply

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

12 − 4 =