freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../basic-javascript/find-the-length-of-a-string/index.md

14 lines
408 B
Markdown
Raw Normal View History

---
title: Find the Length of a String
localeTitle: 找到字符串的长度
---
## 找到字符串的长度
字符串具有称为“长度”的**属性** (特征)。您所要做的就是在字符串/变量之后标记它。
```
var str1 = "Hello";
var length1 = str1.length; // This returns 5
var length2 = " Camper".length; // This returns 7 because the space is counted as one character.
```