We can use the “find” method for that:
let customers = [
{ id: 0, name: ‘riya’ },
{ id: 1, name: ‘john’ },
{ id: 2, name: ‘mary’ }
];
let customer = customers.find(cust => cust.name === ‘mary’ );
console.log(customer);
--> { id: 2, name: ‘mary’ }