Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to use Array.prototype.find() to search for a single object in an array/api response.
// MDN Docs:
const friends = [
{ id: 0, name: "joey", quote: "How you doin?" },
{ id: 1, name: "ross", quote: "We were on a break" },
{ id: 2, name: "phoebe", quote: "She’s your lobster" }
const findFriendById = id => {
return friends.find(friend => === id);
console.log(findFriendById(0)); // Object {id: 0, name: "joey", quote: "How you doin?"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment