DEV Community

Karleb
Karleb

Posted on

58. Length of Last Word

https://leetcode.com/problems/length-of-last-word/?envType=daily-question&envId=2024-04-01

/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLastWord = function(s) {
   const words =  s.trim().split(' ')

   return words[words.length - 1].length
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)