Say I have the following:
const allowedDomains=[
{"domain":"abc.com","apiKey":"1","from":"Goofy"},
{"domain":"def.com","apiKey":"2","from":"Mickey Mouse"},
{"domain":"chi.com","apiKey":"3","from":"Donald Duck"},
];
I have two values in my code that are:
let domain = 'abc.com';
let apiKey = '1';
I want to check if there is an entry in the array that satisfies both conditions. So the above should return true.
If the values are:
let domain = 'abc.com';
let apiKey = '2';
it should return false.
I thought to use find
but don’t know how to use it with two conditions. What is the quickest way to do it?
With one condition it could be:
let from = allowedDomains.find(a => a.domain === domain)?.from;
What for two conditions?