1//indexOf getting index of array element, returns -1 if not found
2var colors=["red","green","blue"];
3var pos=colors.indexOf("blue");//2
4
5//indexOf getting index of sub string, returns -1 if not found
6var str = "We got a poop cleanup on isle 4.";
7var strPos = str.indexOf("poop");//9
1function indexOf(arr, value) {
2 for (let [i, e] of arr.entries()) {
3 if (value == e) return i;
4 }
5 return -1;
6}
7indexOf([1,2,3], 2); //returns 1
1const fruits = ["apple", "banana", "cantaloupe", "blueberries", "grapefruit"];
2
3const index = fruits.findIndex(fruit => fruit === "blueberries");
4
5console.log(index); // 3
6console.log(fruits[index]); // blueberries
7