UNPKG

575 BJavaScriptView Raw
1
2
3 /**
4 * Array indicesOf
5 */
6 function indicesOf(arr, item, fromIndex) {
7 var results = [];
8 if (arr == null) {
9 return results;
10 }
11
12 fromIndex = typeof fromIndex === 'number' ? fromIndex : 0;
13
14 var length = arr.length;
15 var cursor = fromIndex >= 0 ? fromIndex : length + fromIndex;
16
17 while (cursor < length) {
18 if (arr[cursor] === item) {
19 results.push(cursor);
20 }
21 cursor++;
22 }
23
24 return results;
25 }
26
27 module.exports = indicesOf;
28