How to search for an element in JavaScript array?

Following is the code for searching an element in JavaScript array −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .find {
      font-size: 20px;
      font-weight: 500;
<h1>JavaScript search an element in array</h1>
<div class="find"></div>
<button class="fillArr">CLICK HERE</button>
<h3>Click on the above button to find lion among the animals</h3>
   function findLion(animal) {
      return animal === "lion";
   let fillEle = document.querySelector(".find");
   let arr = ["cow", "lion", "bull", "tiger"];
   fillEle.innerHTML = arr;
   document.querySelector(".fillArr").addEventListener("click", () => {
      fillEle.innerHTML = arr.find(findLion);


The above code will produce the following output −

On clicking the ‘CLICK HERE’ button −