1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- const array1 = [5, 12, 8, 130, 44];
- const found = array1.find((element) => element > 10);
- console.log(found);
- function find(target, callbackFn, thisArg) {
-
- if (!Array.isArray(target)) {
- return undefined;
- }
- for (let i = 0, l = target.length; i < l; i++) {
- let cur = target[i];
- let ret = callbackFn.call(thisArg, cur, i, target);
- if (ret) {
- return cur;
- }
- }
- }
- console.log(array1.findIndex((e) => e > 10));
- console.log(array1.findIndex((e) => e > 1000));
|