I am providing the following code snippet:
var users = [
{
name: 'Mark',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8fe2eefde4cfe2eee6e3a1ece0e2">[email protected]</a>',
age: 28,
address: 'England',
val: true
},
{
name: 'John',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f9939691978a9697b994989095d79a9694">[email protected]</a>',
age: 25,
address: 'USA'
},
{
name: 'Tom',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccb8a3a18ca1ada5a0e2afa3a1">[email protected]</a>',
age: 35,
address: 'England'
}];
let res = users.find(
user => (user.name === 'John' || user.name === 'Tom'
|| user.val === true),
);
console.log(res);
How can I prioritize searching by 'name'
, as currently the result is showing object with name Mark
. I want to get the object with name John
if it exists, or Tom
, and if no names are found, then search by val
.