es6 filter 过滤

两数组ab,b数组中如果存在a相同属性值,便存起来

let arr1=[{id:1,name:'网'},{id:2,name:'二位'}]
 let arr2=[{id:1,name:'问问'},{id:3,name:'多少'},{id:44,name:'多少'},{id:45,name:'多少'},]
  let add=arr2.filter(item=>arr1.some(ele=>ele.id===item.id))
  console.log(add)




var post = {id:4,title:"javascript"};
var comments = [
    {postId:4,content:'Angular4'},
    {postId:2,content:'VUE.js'},
    {postId:3,content:'Node.js'},
    {postId:4,content:'React.js'},
];
function commentsForPost(post,comments){
    return comments.filter(function(comment){
        return comment.postId === post.id;
    })
}
console.log(commentsForPost(post,comments))

地址一

地址二

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容