![Find a specific object in an array of objects](https://javascriptsource.com/wp-content/uploads/2022/09/Find-a-specific-object-in-an-array-of-objects-702x526.jpg)
This is arguably one of the most common tasks you’ll need to accomplish in the JS world. Iterating through an array of objects to find a specific one. The find
method is our friend here. Simply plugin the selection criteria using an anonymous function as the argument and you’re set:
let customers = [
{ id: 0, name: 'paul' },
{ id: 1, name: 'jeff' },
{ id: 2, name: 'mary' }
];
let customer = customers.find(cust => cust.name === 'jeff');
console.log(customer);
--> { id: 1, name: 'jeff' }
Source
https://levelup.gitconnected.com/6-javascript-code-snippets-for-solving-common-problems-33deb6cacef3