vue數組的遍歷 filter和find用法


功能是有一個總數組  一個分數組    分數組包含在總數組中,把總數組中和分數組不同的數組元素篩選出來
this.AllLIstcommend : 總數組
this.userChannel    : 分數組


computed: { //計算屬性 recommendChannele () { const channels
= [] //新建一個新數組 this.AllLIstcommend.filter((item, index) => { //從總數組中篩選遍歷 item就是每個數組元素 const ret = this.userChannel.find(userChannel => { //從分數組中找每個元素 當總數組元素等於分數組元素 return userChannel.id === item.id         //說明一樣 不符合要求 }) if (!ret) { channels.push(item) // 不一樣 符合要求 (總數組中和分數組不同的數組元素篩)
} }) // 把計算結果返回 return channels } }      //計算屬性要返回結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM