2021-06-15 03:34:20 +09:00
---
id: bd7123c9c452eddfaeb5bdef
title: Usare la notazione parentesi per trovare l'n-ultimo carattere dalla fine di una stringa
challengeType: 1
videoUrl: 'https://scrimba.com/c/cw4vkh9'
forumTopicId: 18344
dashedName: use-bracket-notation-to-find-the-nth-to-last-character-in-a-string
---
# --description--
È possibile utilizzare lo stesso principio che abbiamo appena usato per recuperare l'ultimo carattere in una stringa per recuperare il carattere n-ultimo dalla fine.
2021-10-27 15:10:57 +00:00
Ad esempio, puoi ottenere il valore della terzultima lettera della stringa `const firstName = "Augusta"` usando `firstName[firstName.length - 3]`
2021-06-15 03:34:20 +09:00
Esempio:
```js
2021-10-27 15:10:57 +00:00
const firstName = "Augusta";
const thirdToLastLetter = firstName[firstName.length - 3];
2021-06-15 03:34:20 +09:00
```
`thirdToLastLetter` dovrebbe avere un valore stringa `s` .
# --instructions--
Usa < dfn > la notazione a parentesi</ dfn > per trovare il penultimo carattere nella stringa `lastName` .
**Suggerimento:** Prova a guardare l'esempio qui sopra se ti blocchi.
# --hints--
`secondToLastLetterOfLastName` dovrebbe essere la lettera `c` .
```js
assert(secondToLastLetterOfLastName === 'c');
```
Dovresti usare `.length` per ottenere la penultima lettera.
```js
assert(code.match(/\.length/g).length > 0);
```
# --seed--
## --after-user-code--
```js
(function(v){return v;})(secondToLastLetterOfLastName);
```
## --seed-contents--
```js
// Setup
2021-10-27 15:10:57 +00:00
const lastName = "Lovelace";
2021-06-15 03:34:20 +09:00
// Only change code below this line
2021-10-27 15:10:57 +00:00
const secondToLastLetterOfLastName = lastName; // Change this line
2021-06-15 03:34:20 +09:00
```
# --solutions--
```js
2021-10-27 15:10:57 +00:00
const lastName = "Lovelace";
const secondToLastLetterOfLastName = lastName[lastName.length - 2];
2021-06-15 03:34:20 +09:00
```