July 13, 2023
Program to use JavaScript Array indexOf() method
let a = ["JavaScript","Python","Php"];
let b = a.indexOf("Python");
console.log(b);
Output
1
Steps Description
- Declare two variable
a
andb
- Initialize two variable with value of array
a = ["JavaScript","Python","Php"]
andb = a.includes("Python")
- 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. - The value of
b
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript Array indexOf() method