Search an array for the item "Apple": - Javascript Array

Javascript examples for Array:lastIndexOf

Description

Search an array for the item "Apple":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from ww  w  .  j  a  va 2s  .com*/
    var fruits = ["Banana","Orange","Apple","Mango","Banana","Orange","Apple","Mango"];
    var a = fruits.lastIndexOf("Apple");
    var x = document.getElementById("demo");
    x.innerHTML = a;
}
</script>

</body>
</html>

Related Tutorials