How to return the full object once it`s been found?

Mar*_*ner 1 javascript arrays

So starting from an array of objects I need to find if any of them are called Google. If so I need to return the full object. Now It is returning true

const companies = [ { id: 1, username: 'facebook', website: 'www.facebook.com' }, { id: 2, username: 'google', website: 'www.google.com' }, { id: 3, username: 'linkedin', website: 'www.linkedin.com' } ]
const checkCompany = company => company.name === "google";

console.log(companies.some(checkCompany)); // true
Run Code Online (Sandbox Code Playgroud)

Mah*_*Ali 5

some() returns a Boolean.You can use Array.prototype.find() which returns the value of first element in array. If no element in array matches condition then it returns undefined

const companies = [ { id: 1, username: 'facebook', website: 'www.facebook.com' }, { id: 2, username: 'google', website: 'www.google.com' }, { id: 3, username: 'linkedin', website: 'www.linkedin.com' } ]
const res = companies.find(x => x.username === "google");
console.log(res)
Run Code Online (Sandbox Code Playgroud)