1 | import globalize from './internal/globalize';
|
2 |
|
3 | /**
|
4 | * Finds the index of an element in the array.
|
5 | *
|
6 | * @param {Array} The array being searched.
|
7 | * @param {Mixed} item Element which will be searched for.
|
8 | * @param {Integer} fromIndex The index from which the item will be searched. Negative values will search from the end of the array.
|
9 | *
|
10 | * @returns {Integer}
|
11 | */
|
12 | function indexOf (array, item, fromIndex) {
|
13 | var length = array.length;
|
14 |
|
15 | if (!fromIndex) {
|
16 | fromIndex = 0;
|
17 | } else if (fromIndex < 0) {
|
18 | fromIndex = Math.max(0, length + fromIndex);
|
19 | }
|
20 |
|
21 | for (var i = fromIndex; i < length; i++) {
|
22 | if (array[i] === item) {
|
23 | return i;
|
24 | }
|
25 | }
|
26 |
|
27 | return -1;
|
28 | }
|
29 |
|
30 | globalize('indexOf', indexOf);
|
31 |
|
32 | export default indexOf;
|