# 58. Length of Last Word

### Leetcode

#### <https://leetcode.com/problems/length-of-last-word/>

### 題目

Given a string `s` consisting of some words separated by some number of spaces, return *the length of the **last** word in the string.*

A **word** is a maximal substring consisting of non-space characters only.

### 解答 <a href="#ti-jie" id="ti-jie"></a>

* **方法一**

```
var lengthOfLastWord = function(s) {
    const arr = s.trim().split(' ');
    return arr[arr.length - 1].length;
};
```

Runtime: 76 ms, faster than 60.73% of JavaScript online submissions for Length of Last Word.

Memory Usage: 39.2 MB, less than 12.68% of JavaScript online submissions for Length of Last Word.
