Created
November 27, 2020 10:09
-
-
Save kieranbarker/c7213381af3cd62f2f7847c28b2e2cb9 to your computer and use it in GitHub Desktop.
Get the last word in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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