Skip to content

Instantly share code, notes, and snippets.

@kieranbarker
Created November 27, 2020 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kieranbarker/c7213381af3cd62f2f7847c28b2e2cb9 to your computer and use it in GitHub Desktop.
Save kieranbarker/c7213381af3cd62f2f7847c28b2e2cb9 to your computer and use it in GitHub Desktop.
Get the last word in a string
/**
* Get the last word in a string
* @param {String} str The string
* @returns {String} The last word
*/
function getLastWord (str) {
return str.trim().split(/\s+/).pop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment