Debian Codegraph @

packages/popper/src/utils/findIndex.js

raw
1 import find from './find';
2
3 /**
4 * Return the index of the matching object
5 * @method
6 * @memberof Popper.Utils
7 * @argument {Array} arr
8 * @argument prop
9 * @argument value
10 * @returns index or -1
11 */
12 export default function findIndex(arr, prop, value) {
13 // use native findIndex if supported
14 if (Array.prototype.findIndex) {
15 return arr.findIndex(cur => cur[prop] === value);
16 }
17
18 // use `find` + `indexOf` if `findIndex` isn't supported
19 const match = find(arr, obj => obj[prop] === value);
20 return arr.indexOf(match);
21 }