JavaScript String inizia con()
Esempi
Inizia dalla posizione 0:
let text = "Hello world, welcome to the universe.";
text.startsWith("Hello");
Inizia dalla posizione 6:
let text = "Hello world, welcome to the universe.";
text.startsWith("world", 7);
Definizione e utilizzo
Il startsWith()
metodo restituisce true
se una stringa inizia con una stringa specificata.
Altrimenti ritorna false
.
Il startsWith()
metodo fa distinzione tra maiuscole e minuscole.
Vedi anche il endsWith()
metodo.
Sintassi
string.startsWith(searchValue, start)
Parametri
Parameter | Description |
searchValue | Required. The string to search for. |
start | Optional. Start position. Default is 0. |
Valore di ritorno
Tipo | Descrizione |
Un booleano | Restituisce true se la stringa inizia con il valore. Altrimenti ritorna false . |
Supporto browser
startsWith()
è una funzione ECMAScript6 (ES6).
ES6 (JavaScript 2015) è supportato in tutti i browser moderni:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
startsWith()
non è supportato in Internet Explorer 11 (o versioni precedenti).