String JavaScript inclui()
Exemplos
Verifique se uma string inclui "world":
let text = "Hello world, welcome to the universe.";
let result = text.includes("world");
let text = "Hello World, welcome to the universe.";
let result = text.includes("world", 12);
Mais exemplos abaixo.
Definição e uso
O includes()
método retorna true
se uma string contém uma string especificada.
Caso contrário, ele retorna false
.
O includes()
método diferencia maiúsculas de minúsculas.
Sintaxe
string.includes(searchvalue, start)
Parâmetros
Parameter | Description |
searchvalue | Required. The string to search for. |
start | Optional. The position to start from. Default value is 0. |
Valor de retorno
Modelo | Descrição |
Um booleano. | true se a string contiver o valor, caso contrário false . |
Mais exemplos
Comece na posição 12:
let text = "Hello world, welcome to the universe.";
let result = text.includes("world", 12);
Suporte ao navegador
includes()
é 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 |
includes()
não é compatível com o Internet Explorer 11 (ou anterior).