UNPKG

584 BJavaScriptView Raw
1
2
3 /**
4 * Array.indexOf
5 */
6 function indexOf(arr, item, fromIndex) {
7 fromIndex = fromIndex || 0;
8 if (arr == null) {
9 return -1;
10 }
11
12 var len = arr.length,
13 i = fromIndex < 0 ? len + fromIndex : fromIndex;
14 while (i < len) {
15 // we iterate over sparse items since there is no way to make it
16 // work properly on IE 7-8. see #64
17 if (arr[i] === item) {
18 return i;
19 }
20
21 i++;
22 }
23
24 return -1;
25 }
26
27 module.exports = indexOf;
28