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
})