Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the last word of a sentence using jQuery?

How can I get the last word of a sentence using jQuery?

Examples:

  • get the last word of a sentence should return sentence
  • get the last word should return word
like image 909
Leo T Abraham Avatar asked Jan 08 '23 21:01

Leo T Abraham


1 Answers

try this

var lastword = str.split(" ").pop();
like image 72
user1844933 Avatar answered Jan 19 '23 03:01

user1844933