.length
来查找String
值的长度。 "Alan Peter".length; // 10
例如,如果我们创建了一个变量var firstName = "Charles"
,我们可以通过使用firstName.length
属性找出字符串"Charles"
长度。 .length
属性计算lastName
变量中的字符数,并将其分配给lastNameLength
。 lastNameLength
应该等于8。
testString: 'assert((function(){if(typeof lastNameLength !== "undefined" && typeof lastNameLength === "number" && lastNameLength === 8){return true;}else{return false;}})(), "lastNameLength
should be equal to eight.");'
- text: 您应该使用.length
来获取lastName
的长度,如下所示: lastName.length
。
testString: 'assert((function(){if(code.match(/\.length/gi) && code.match(/\.length/gi).length >= 2 && code.match(/var lastNameLength \= 0;/gi) && code.match(/var lastNameLength \= 0;/gi).length >= 1){return true;}else{return false;}})(), "You should be getting the length of lastName
by using .length
like this: lastName.length
.");'
```