7 examples of 'findindexof' in JavaScript

Every line of 'findindexof' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
13function findIndexOf(arr, cb) {
14 let idx = -1;
15 arr.some((d, i) => {
16 if (cb(d, i)) {
17 idx = i;
18 return true;
19 }
20 return false;
21 });
22 return idx;
23}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

236function _indexOf(array, searchElement, fromIndex)
237{
238 if(array.indexOf)
239 return array.indexOf(searchElement, fromIndex);
240 else {
241 if(typeof(fromIndex) != "number")
242 fromIndex = 0;
243
244 for(var index = 0; index < array.length; index ++)
245 {
246 if(array[index] === searchElement)
247 return index;
248 }
249
250 return -1;
251 }
252}
236function indexOf(needle, list) {
237 _assert(isList(list), "indexOf expects a needle and a list");
238 var i, l;
239 for (i = 0, l = list.length; i < l; ++i) {
240 if (needle === list[i]) { return i; }
241 }
242 return -1;
243}
10export function findIndex<A>(array: A[], callback: (item: A) => boolean) {
11 const found = array.find(callback);
12 if (found) {
13 return array.indexOf(found);
14 }
15 return -1;
16}
11export function findFirst(array, p) {
12 var low = 0, high = array.length;
13 if (high === 0) {
14 return 0; // no children
15 }
16 while (low < high) {
17 var mid = Math.floor((low + high) / 2);
18 if (p(array[mid])) {
19 high = mid;
20 }
21 else {
22 low = mid + 1;
23 }
24 }
25 return low;
26}
12export function findFirst<T>(array: T[], p: (x: T) => boolean): number {
13 let low = 0, high = array.length;
14 if (high === 0) {
15 return 0; // no children
16 }
17 while (low < high) {
18 let mid = Math.floor((low + high) / 2);
19 if (p(array[mid])) {
20 high = mid;
21 } else {
22 low = mid + 1;
23 }
24 }
25 return low;
26}
88export function findNthIndexOfX(array, n = 1, filter) {
89 if (n < 0) {
90 const revIndex = findNthIndexOfX([...array].reverse(), -n, filter);
91
92 return revIndex === -1 ? -1 : array.length - 1 - revIndex;
93 }
94 let occurrences = 0;
95
96 return array.findIndex(event => {
97 if (filter(event)) {
98 occurrences += 1;
99 if (occurrences === n) {
100 return true;
101 }
102
103 return false;
104 }
105
106 return false;
107 });
108}

Related snippets