JavaScript

July 13, 2023

How to use JavaScript Array indexOf()

Program to use JavaScript Array indexOf() method


let a = ["JavaScript","Python","Php"];
let b = a.indexOf("Python");
console.log(b);

Output


1

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = ["JavaScript","Python","Php"] and b = a.includes("Python")
  3. Array IndexOf() method returns the index value of the array if it is found in the given array and returns -1 if it is not found.
  4. The value of b variable is displayed with the help of console.log inbuilt function

by : Suhel Akhtar

Quick Summary:

JavaScript Array indexOf() method