Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by www.javascripttutorial.net #
 
PREVIOUS NEXT
Tagged: #indexOF #js
ADD COMMENT
Topic
Name
6+5 =