const result = array.find((element, index, array) => {
// 返回一个条件,用于查找符合条件的元素
});
element:当前遍历到的数组元素
index:遍历到所有数组元素的索引
array:调用 find 的数组本身
例如,假设我们有一个数组:
const numbers = [1, 2, 3, 4, 5];
const result = numbers.find((element) => {
return element >= 3;
});
console.log(result); // 输出: 3