7+ JavaScript Blank Space Remover Programs

This post contains a total of 7+ JavaScript Blank Space Remover Program Examples with Source Code. All these Blank Space Remover Programs are used to remove Blank / White Space from Strings, and these programs are made using JavaScript.

You can use the source code of these examples with credits to the original owner.

Related Posts

JavaScript Blank Space Remover Programs

1. By ROHIT KANOJIYA

Made by ROHIT KANOJIYA. Simple JavaScript program to remove space from a string, enter the string in the input box then click the submit button to get its output. Source

JavaScript Blank Space Remover Program by Rohit Kanojiya
<!DOCTYPE html>
<html>
  <head>
     <title></title>
     <link href="https://fonts.googleapis.com/css?family=Balthazar|Cambay|Handlee&display=swap" rel="stylesheet">  
  <style>
      *{
 margin:0;
 padding:0;
 box-sizing:border-box;
}

body{
  background-color:skyblue;
}

.container{
    width:85%;
    margin:auto;
    border:3px solid blue;
  /*
    box-shadow:1px 1px 5px crimson,
              -1px -1px 5px crimson;*/
}

.header{
    padding:3vh 0;
    background-color:tomato;
}

.header h1{
  color:#fff;
  text-align:center;
  letter-spacing:0.1em;
  font-family:Balthazar,sans-sarif;
}

.input-part{
    padding:2vh 1vh;
    background-color:#0D5C70; /*172A3A;*/
}

label[for="string"]{
    display:block;
    text-align:center ;
    margin:1rem ;
    font-size:1.4rem;
    color:#fff;
}

#string,#btn{
    display:block;
    width:90%;
    height:3rem;
    font-size:1rem;
    margin:1rem auto;
    padding:0.5em;
    border-radius:5px;
    border:0;
    outline:none;
}

#btn{
  
  color:#fff;
  border:0;
  font-weight:bold;   
  width:40%;
  background-color:#247B7B;
  box-shadow:1px 1px 5px lightblue,
             -1px -1px 5px lightblue; 
}
#btn:hover{
  background-color:#78CDD7;
  color:#0D5C63;
}

#output{ 
  display:none;
  padding:1rem;
  font-size:1.1rem;
  line-height:1.5;
  background-color:#ddd;
  word-wrap:wrap;
  word-break:break-all;
}

@media only screen and (max-width:468px){
  .container{
      width:100%;
      margin:0 auto;
  }
}

      </style>
  </head>
<body>

 <div class="container">
   <div class="header">
     <h1>Remove Space From String</h1>
   </div>

   <div class="input-part">
     <label for="string">Enter a String:</label>
     <input id="string" type="text" placeholder="Enter a String">
     <input id="btn" onclick="removeSpace()" type="submit"         
      value="Submit">
   </div>   
   
   <div id="output">    
    <h3>String Without Space:</h3>
    <p id="show"></p> 
   </div>
   
 </div>     
<script>
    function removeSpace()
{
 var string=document.getElementById('string');
 var output=document.getElementById('output');
 var show=document.getElementById('show');

 var str=string.value;
 
 if(str==""){
  alert("⚠️  Enter a String.");
  return;
 }
 var newstr="-> ";
 
 str.split(' ').forEach(loop);
 function loop(s){
  if(s!=" ")
   newstr+=s;
  }

 output.style.display="block";
 show.innerHTML=newstr;
}

    </script>
</body>
</html>

2. By Mykola Fedoseev

Made by Mykola Fedoseev. Program to remove blank space from string in Realtime. Source

JavaScript Blank Space Remover Program by mykola fedoseev
<!DOCTYPE html>
<html>
    <head>
        <title>Remove spaces</title>
        <style>
            body {
    background: #fed;
}
            </style>
    </head>
    <body>
        <h1></h1>
        <p>Enter text here:
        <input id="a" size="50" oninput="b.value=a.value.replace(/ /g,'')"/></p>
        <p>Text without spaces: 
        <input id="b" size="50"readonly="readonly"/></p>
    </body>
</html>

3. By Danijel Ivanović

Made by Danijel Ivanović. Simple JavaScript White space remover. Source

JavaScript Blank Space Remover Program by danijel ivanovic
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
  <h1 align="center"> Heading</h1>
</head> 
<body align="center"> 
  <div id="container">
    <div id="intro"> 
      <h2> Remove Spaces from a String!</h2>
    </div>
    
    <p id="inputString">
      <strong> Please, enter a String with White Spaces <br /> in the text field below!</strong></p>
    
    <input type="text" class="custom" id="input" placeholder="Enter a String ...!"/>
    <br />
    
    <div id="answer"></div>
    
  <p>
    <strong> Click the Button to Remove White Spaces!</strong></p>
  
  <button id="button2" class="button" onclick="removeSpace()"> Remove Spaces!</button>
  <br />
  
   <p id="result"> by @booleanmaybe Happy SoloLearning ;) </p>
</div> 
<script>
function removeSpace(str) {
  str = document.getElementById('result').innerHTML; 
  const res = str.replace(/\s/g, '');

  document.getElementById('result').innerHTML = res;
}
</script>
</body>
</html>

4. By DAB

Made by DAB. Single line Program to Remove empty spaces from strings. Source

qw er ty
qwerty
document.write(prompt("Enter a string:").split(" ").join(""));

5. By Kavi

Made by Kavi. Basic JavaScript program that takes string input using prompt and outputs the string without spaces in between characters. Source

Real:qw er ty

Space Removed:qwerty
<!DOCTYPE html>
<html>
    <head>
        <title></title>
    <style>
        body {
    background-color:#de2f36;
    font-weight:900;
    font-size:30px;
}
        </style>
    </head>
    <body>
       <script>
               str = prompt('Enter A string plz.. With Many Spaces');
    
    rem = str.split(" ").join('');
    alert(rem);

    document.write("Real:"+str+"</br></br>");
    document.write("Space Removed:"+rem);
           </script>
    </body>
</html>

6. By Mazin Ayash

Made by Mazin Ayash. Source

you entered: de mo
demo
var str = prompt ("enter a string with white spaces");
document.write("remove white spaces from a string<br>");
document.write("you entered:    "+str+"<br>"+str.replace(/\s/g,''));

7. By Vikash Pal

Made by Vikash Pal. Basic program that prints out a input string without spaces in the console log. Source

HelloWorld! 

function removeWhitespace(str){
    str = str.replace(/\s+/g, "");
    return str;
}

console.log(removeWhitespace("Hello World!"));

8. By Aaron Sarkissian

Made by Aaron Sarkissian. JavaScript Regex white space remover. Source

abc
const str = "ab c";

console.log(str.replace(/\s/g, ''));