Hi, I want to display only the first word in a sentence.Please let me know how can I do this by using Javascript. Thanks in advance.
Maybe you should trim the sentence first so you won't hit a problem if the string starts with spaces : var s="This is a sentence"; s= s.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); var first_word=s.split(" ")[0];