How to use JavaScript Array indexOf()
Array indexOf()
On this page
Array indexOf() method
Program to use JavaScript Array indexOf() method
let a = ["HTML","CSS","JavaScript"];
let b = a.indexOf("CSS");
console.log(b);
Output
1
Steps Description
- Declare two variable a and b
- Initialize two variable with value of array a = [“HTML”,”CSS”,”JavaScript”] and b = a.includes(“CSS”)
- 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