Return First Character of each word in a string - Javascript String

Javascript examples for String:substring

Description

Return First Character of each word in a string

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 w w  .j a  va2  s. c om*/
var name = "John P White This Test",
    data = name.split(' '), output = "";
for ( var i = 0; i < data.length; i++) {
    output += data[i].substring(0,1);
}
console.log(output);
    }

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

Related Tutorials