Array findIndex() function in JavaScript

The findIndex() function in JavaScript returns the index of the first element value that satisfy a given condition in an array.

Following is the code for the array find() function −


 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;
   .findIndex {
      font-size: 20px;
      font-weight: 500;
<h1>JavaScript Array FindIndex() example</h1>
<div class="findIndex"></div>
<button class="findArr">CLICK HERE</button>
<h3>Click on the above button to get the index of lion in the array</h3>
   function findLion(animal) {
      return animal === "lion";
   let fillEle = document.querySelector(".findIndex");
   let arr = ["cow", "lion", "bull", "tiger"];
   fillEle.innerHTML = arr;
   document.querySelector(".findArr").addEventListener("click", () => {
      fillEle.innerHTML = arr.findIndex(findLion);


On clicking the ‘CLICK HERE’ button the index of lion will be returned as follows −