filter()的返回值


Arr.filter()方法

filter(callback(element[, index[, array]])[, thisArg))

参数:

1.回调函数,

2.元素

3.元素的索引

4.调用filter的数组

5.执行callback时的this的值

最后要返回一个新数组根据判断条件返回的true和false,有选择的添加到新数组当中

//缩写
const checkedFruit = this.fruitList.filter(v => {
                        /*如果是true就返回,如果是false就不返回*/
                        return v.isChecked
})
//全写
const checkedFruit = this.fruitList.filter(v => {
                       if(v.isChecked===true)return true
                       if(v.isChecked===false)return false
                    })


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM