La stringa JavaScript finisce con()
Esempi
Controlla se una stringa termina con "world":
let text = "Hello world";
let result = text.endsWith("world");
let text = "Hello World";
let result = text.endsWith("world");
Altri esempi di seguito.
Definizione e utilizzo
Il endsWith()
metodo restituisce true
se una stringa termina con una stringa specificata.
Altrimenti ritorna false
.
Il endsWith()
metodo fa distinzione tra maiuscole e minuscole.
Vedi anche il startswith()
metodo.
Sintassi
string.endsWith(searchvalue, length)
Parametri
Parameter | Description |
searchvalue | Required. The string to search for. |
length | Optional. The length of the string to search. Default value is the length of the string. |
Valore di ritorno
Tipo | Descrizione |
Un booleano | true se la stringa termina con il valore, altrimenti false . |
Altri esempi
Controlla se i primi 11 caratteri di una stringa terminano con "mondo":
let text = "Hello world, welcome to the universe.";
text.endsWith("world", 11);
Supporto browser
endsWith()
è una funzione ECMAScript6 (ES6).
ES6 (JavaScript 2015) è supportato in tutti i browser moderni:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
endsWith()
non è supportato in Internet Explorer 11 (o versioni precedenti).