0
Person, I’m with this code:
const arrayOne = ['jean','geleia','gean','ea games', 'e1'];
function buscar(){
arrayOne.forEach(function(valor){
const teste1 = document.getElementById('valorInput').value;
if(teste1 === valor){
alert (true)
} else {
alert(false)
}
})
}
<html>
<body>
<input id='valorInput'/>
<button onClick='buscar()'> Buscar </button>
<h1 id='resultado'> Resultado </h1>
</body>
</html>
I wanted to know how I do so that when I type the letter 'a' it returns true
in the words that exist the letter 'a'?
Someone could help me ?
This seems to me an XY problem. If the idea is to find the names that correspond to what the user wrote the best is to use
filter
withconst nomesFiltrados = arrayOne.filter(nome=>nome.indexOf(teste1) !== -1);
– Isac