You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1088,6 +1089,34 @@ Each proposal for an ECMAScript feature goes through the following maturity stag
1088
1089
console.log(factorial(1000));
1089
1090
console.log(factorial(10000));
1090
1091
```
1092
+
24. ### Array find methods
1093
+
ES6 introduced few array methods and two of them are `Array.find()` and `Array.findIndex()`.
1094
+
1095
+
**Array.find()**
1096
+
This method returns the value of the first element in an array that satisfies the given test. Let's take an example of array with all even elements except one element and use `find` method to find the odd element.
1097
+
1098
+
```js
1099
+
let arr = [2, 4, 5, 6, 8, 10];
1100
+
1101
+
functionisOdd(i) {
1102
+
return i %2!==0;
1103
+
}
1104
+
1105
+
console.log(arr.find(isOdd)); // 5
1106
+
```
1107
+
**Array.findIndex()**
1108
+
1109
+
This method returns the index of the first element in the array that satisfies the given test. Let's take an example of array with all even elements except one element and use `findIndex` method to find the index of odd element.
0 commit comments