用法

  1. find() 方法返回通过测试(函数内判断)的数组的第一个元素的值。

  2. 如果没有符合条件的元素返回 undefined

  3. find() 对于空数组,函数是不会执行的。

  4. find() 并没有改变数组的原始值。

  5. array.find(function(currentValue, index, arr),thisValue),其中currentValue为当前项,index为当前索引,arr为当前数组

实例


        let test = [1, 2, 3, 4, 5];
        let a = test.find(item => item > 3);
        console.log(a); //4

        let b = test.find(item => item == 0);
        console.log(b); //undefined
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐