Answers for "make indexOF in js"

49

javascript indexof

//indexOf getting index of array element, returns -1 if not found
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2

//indexOf getting index of sub string, returns -1 if not found
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9
Posted by: Guest on June-27-2019
1

make indexOF in js

function indexOf(arr, value) {
  for (let [i, e] of arr.entries()) {
    if (value == e) return i;
  }
  return -1;
}
indexOf([1,2,3], 2);                     //returns 1
Posted by: Guest on November-04-2020
0

indexof js

const fruits = ["apple", "banana", "cantaloupe", "blueberries", "grapefruit"];

const index = fruits.findIndex(fruit => fruit === "blueberries");

console.log(index); // 3
console.log(fruits[index]); // blueberries
Posted by: Guest on June-03-2021
9

indexof javascript

Array.indexOf(searchElement, fromIndex)
Posted by: Guest on January-14-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language