-1
I’d like to know how I get around a Array
and return its value.
In this case, it would be to compare whether a word/letter typed in a input
has already been inserted before by another input
and if it was, it would have to be removed.
-1
I’d like to know how I get around a Array
and return its value.
In this case, it would be to compare whether a word/letter typed in a input
has already been inserted before by another input
and if it was, it would have to be removed.
1
Here is an example using includes to check whether or not the array value exists.
Other :
Example using foreach :
var palavras = ["mateus", "veloso", "vermelho"];
$(function(){
$('#bt').click(function(){
let valor = $('#teste').val();
if(palavras.includes(valor)){
alert('palavra encontrada no array');
}else{
alert('palavra não encontrada no array');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="teste">
<input type="button" value="verificar" id="bt">
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
for
,for...in
,for...of
,while
,Array.protorype.forEach
, see if any fit you.– Woss
I don’t know what this has to do with object orientation
– Denis Rudnei de Souza