String JavaScript terminaCom()
Exemplos
Verifique se uma string termina com "world":
let text = "Hello world";
let result = text.endsWith("world");
let text = "Hello World";
let result = text.endsWith("world");
Mais exemplos abaixo.
Definição e uso
O endsWith()
método retorna true
se uma string termina com uma string especificada.
Caso contrário, ele retorna false
.
O endsWith()
método diferencia maiúsculas de minúsculas.
Veja também o startswith()
método.
Sintaxe
string.endsWith(searchvalue, length)
Parâmetros
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. |
Valor de retorno
Modelo | Descrição |
Um booleano | true se a string terminar com o valor, caso contrário false . |
Mais exemplos
Verifique se os 11 primeiros caracteres de uma string terminam com "world":
let text = "Hello world, welcome to the universe.";
text.endsWith("world", 11);
Suporte ao navegador
endsWith()
é um recurso ECMAScript6 (ES6).
O ES6 (JavaScript 2015) é compatível com todos os navegadores modernos:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
endsWith()
não é compatível com o Internet Explorer 11 (ou anterior).