Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Oi pessoal estou tentando buscar a posição do Array literal com o indexOf() mais ele retorna -1, será que estou fazendo correto?
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the position of the element "Apple":</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var fruits = [{"id": 1, "nome": "Banana"}, {"id": 1, "nome": "Orange"}, {"id": 1, "nome": "Apple"}, {"id": 1, "nome": "Mango"}];
var a = fruits.indexOf("Orange");
document.getElementById("demo").innerHTML = a;
}
</script>
<p><b>Note:</b> The indexOf method was introduced in JavaScript 1.6, and does not work in Internet Explorer 8 and earlier versions.</p>
</body>
</html>Carregando comentários...