--- id: bd7123c9c452eddfaeb5bdef title: Use Bracket Notation to Find the Nth-to-Last Character in a String challengeType: 1 videoUrl: '' localeTitle: 使用括号表示法查找字符串中的第N个到最后一个字符 --- ## Description
您可以使用我们刚刚用于检索字符串中最后一个字符的相同原理来检索N到最后一个字符。例如,您可以使用firstName[firstName.length - 3]获取var firstName = "Charles"字符串的倒数第三个字母的值
## Instructions
使用括号表示法查找lastName字符串中倒数第二个字符。 暗示
如果卡住,请尝试查看thirdToLastLetterOfFirstName变量声明。
## Tests
```yml tests: - text: secondToLastLetterOfLastName应为“c”。 testString: 'assert(secondToLastLetterOfLastName === "c", "secondToLastLetterOfLastName should be "c".");' - text: 你必须使用.length来获得倒数第二个字母。 testString: 'assert(code.match(/\.length/g).length === 2, "You have to use .length to get the second last letter.");' ```
## Challenge Seed
```js // Example var firstName = "Ada"; var thirdToLastLetterOfFirstName = firstName[firstName.length - 3]; // Setup var lastName = "Lovelace"; // Only change code below this line var secondToLastLetterOfLastName = lastName; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```