比较旧请求list和新的请求list对比,将新的数据过滤出来到resultList
import _ from "lodash";
const oldList = [{commentId:1},{commentId:2},{commentId:3},{commentId:4},{commentId:5},{commentId:6},{commentId:7},{commentId:8}];
const newList = [{commentId:5},{commentId:6},{commentId:7},{commentId:8},{commentId:9},{commentId:10},{commentId:11},{commentId:12},{commentId:13},];
const oldIndexList = oldList.map(item=>item.commentId)
const newIndexList = newList.map(item=>item.commentId)
const resultIndexList = _.difference(newIndexList,oldIndexList);
let resultList = [];
resultIndexList.forEach(item=>{
resultList.push(newList.find(key=>key.commentId===item))
})
console.log(resultList)