Skip to content

Instantly share code, notes, and snippets.

@mannuelf
Created January 1, 2017 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mannuelf/52bba47bc5dd444f215af3283b3d4480 to your computer and use it in GitHub Desktop.
Save mannuelf/52bba47bc5dd444f215af3283b3d4480 to your computer and use it in GitHub Desktop.
find a specific post or thing in an array
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