Get First Word of String Using Javascript

Hi guys today i will tell you through this tutorial that how do we get the first word of any sentence from javascript code.

Get first word of string, Get first word of string in Javascript, Get first word of string Using Javascript, Get first word from Sentence using Javascript, Get first word from Sentence in Javascript or Jquery, javascript get first word/part of a sentence

firstword.html

<script type="text/javascript">
var totalWords = "my name is rahul.";
var firstWord = totalWords.replace(/ .*/,'');
alert(firstWord);
console.log(firstWord);
</script>