xxxxxxxxxx
var arr = ["item", "item2"];
arr.indexOf("item"); // return 0
arr.indexOf("item2") //retrun 1
xxxxxxxxxx
// Sample array
const myArray = [10, 20, 30, 40, 50];
// Element to find
const elementToFind = 30;
// Use indexOf to find the index of the element
const index = myArray.indexOf(elementToFind);
// Check if the element is present in the array
if (index !== -1) {
console.log(`The index of ${elementToFind} is: ${index}`);
} else {
console.log(`${elementToFind} is not present in the array.`);
}