Sitemap
Ricardo Reis

Ricardo Reis

Bitcoin

Press enter or click to view image in full size

includes() JavaScript

Nesse tutorial você vai aprender como usar o método includes() para verificar se uma string contém outra string.

--

English version: https://www.javascripttutorial.net/es6/javascript-string-includes/

O método includes() determina se uma string contém outra string:

Press enter or click to view image in full size

O método includes() retorna true se o searchString existe na string, caso contrário retorna false.

O parâmetro opcional position especifica a posição dentro da string na qual começar a procurar pela searchString. O padrão é zero.

O includes() corresponde à string diferenciando letras maiúsculas e minúscula.

Get Ricardo Reis’s stories in your inbox

Join Medium for free to get updates from this writer.

O exemplo a seguir usa o método includes() para verificar se a string “@” está presente ou não na string email:

Press enter or click to view image in full size

Resultado:

Press enter or click to view image in full size

Outro exemplo:

Press enter or click to view image in full size

Resultado:

Press enter or click to view image in full size

Como mencionado anteriormente, o includes() corresponde à string com distinção entre maiúsculas e minúsculas:

Press enter or click to view image in full size

Resultado:

Press enter or click to view image in full size

Exemplo usando o segundo parâmetro:

Press enter or click to view image in full size

Resultado:

Press enter or click to view image in full size

Veja o índice de todos os tutoriais JavaScript

--

--