Created
January 1, 2017 21:36
-
-
Save mannuelf/52bba47bc5dd444f215af3283b3d4480 to your computer and use it in GitHub Desktop.
find a specific post or thing in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const posts = [ | |
{ id: 1, title: 'New Post'}, | |
{ id: 2, title: 'Old Post'}, | |
]; | |
const comment = { postId: 1, content: 'what great reading' }; | |
function postForComment(posts, comment) { | |
return posts.find(function(post) { | |
return post.id === comment.postId; | |
}); | |
}; | |
postForComment(posts, comment); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment