Remove whitespace in String with for and if statement - Javascript Statement

Javascript examples for Statement:if

Description

Remove whitespace in String with for and if statement

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w  ww.j  a  va2  s .  c  om*/


var x = "Enter sum";
var v='';
for (var i=0; i<=x.length;i++) {
     if (x[i] != " ") {
         v +=x[i];
     }
}
console.log(v);


    }

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

Related Tutorials