10 examples of 'typescript find element in array' in JavaScript

Every line of 'typescript find element in array' 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
7export function findObject (array, property, value) {
8 for (let i = 0; i < array.length; i++) {
9 if (array[i][property] === value) {
10 return array[i]
11 }
12 }
13
14 return null
15}
13function find (array, id) {
14 if(!id) return
15 for (var k in array) {
16 if(array[k].id == id) return array[k]
17 }
18}
432export function find(array, matches) {
433 var index = findIndex(array, matches);
434 if (index !== -1) {
435 return array[index];
436 }
437}
1function __TS__ArrayIndexOf(this: void, arr: T[], searchElement: T, fromIndex?: number): number {
2 const len = arr.length;
3 if (len === 0) {
4 return -1;
5 }
6
7 let n = 0;
8 if (fromIndex) {
9 n = fromIndex;
10 }
11
12 if (n >= len) {
13 return -1;
14 }
15
16 let k: number;
17 if (n >= 0) {
18 k = n;
19 } else {
20 k = len + n;
21 if (k < 0) {
22 k = 0;
23 }
24 }
25
26 for (let i = k; i < len; i++) {
27 if (arr[i] === searchElement) {
28 return i;
29 }
30 }
31
32 return -1;
33}
2export function findIndex(el:HTMLElement):number {
3 if (!el.parentElement) {
4 return -1;
5 }
6
7 const children = Array.from(el.parentElement.children);
8 return children.indexOf(el);
9}
158export function array_item_at(array: T[], index: number): T {
159 if (index >= array.length) {
160 return array[index % array.length];
161 }
162 else if (index < 0) {
163 return array[array.length - (-index % array.length)];
164 }
165 else {
166 return array[index];
167 }
168}
49function indexOf (ary, element) {
50 var i;
51 for (i = 0; i < ary.length; i += 1) {
52 if (ary[i] === element) {
53 return i;
54 }
55 }
56 return -1;
57}
12function find(array, callback) {
13 for (var i = 0; i < array.length; i++) {
14 if (callback(array[i], i, array)) {
15 return array[i];
16 }
17 }
18}
113function find(arr, callback) {
114 return arr[findIndex(arr, callback)];
115}
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}

Related snippets