两数组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
暂无评论内容