2021-06-15 03:34:20 +09:00
---
id: bd7123c9c448eddfaeb5bdef
title: Trovare la lunghezza di una stringa
challengeType: 1
videoUrl: 'https://scrimba.com/c/cvmqEAd'
forumTopicId: 18182
dashedName: find-the-length-of-a-string
---
# --description--
Puoi trovare la lunghezza di un valore `String` scrivendo `.length` dopo la variabile stringa o il stringa letterale.
```js
console.log("Alan Peter".length);
```
2022-04-11 19:34:39 +05:30
Il valore `10` sarà visualizzato nella console. Nota che è contato anche il carattere spazio tra "Alan" e "Peter".
2021-06-15 03:34:20 +09:00
2021-10-27 15:10:57 +00:00
Ad esempio, se avessimo creato una variabile `const firstName = "Ada"` , potremmo scoprire quanto è lunga la stringa `Ada` utilizzando la proprietà `firstName.length` .
2021-06-15 03:34:20 +09:00
# --instructions--
Usa la proprietà `.length` per contare il numero di caratteri nella variabile `lastName` e assegnarla a `lastNameLength` .
# --hints--
Non dovresti cambiare le dichiarazioni della variabile nella sezione `// Setup` .
```js
assert(
2021-10-27 15:10:57 +00:00
code.match(/let lastNameLength = 0;/) & &
code.match(/const lastName = "Lovelace";/)
2021-06-15 03:34:20 +09:00
);
```
`lastNameLength` dovrebbe essere uguale a 8.
```js
assert(typeof lastNameLength !== 'undefined' & & lastNameLength === 8);
```
Dovresti ottenere la lunghezza di `lastName` utilizzando `.length` in questo modo: `lastName.length` .
```js
assert(code.match(/=\s*lastName\.length/g) && !code.match(/lastName\s*=\s*8/));
```
# --seed--
## --seed-contents--
```js
// Setup
2021-10-27 15:10:57 +00:00
let lastNameLength = 0;
const lastName = "Lovelace";
2021-06-15 03:34:20 +09:00
// Only change code below this line
lastNameLength = lastName;
```
# --solutions--
```js
2021-10-27 15:10:57 +00:00
let lastNameLength = 0;
const lastName = "Lovelace";
2021-06-15 03:34:20 +09:00
lastNameLength = lastName.length;
```