Use an array or Set instead:
getList(oauth2Client).then(items => {
const emails = new Set(['[email protected]', '[email protected]']);
for (const item of items) {
if (item.selected && emails.has(item.id)) {
promiseArray.push(getEvents(oauth2Client, item.id, item.backgroundColor));
}
}
});
I'd prefer a Set because it has lower complexity, but with an array, use .includes:
getList(oauth2Client).then(items => {
const emails = ['[email protected]', '[email protected]'];
for (const item of items) {
if (item.selected && emails.includes(item.id)) {
promiseArray.push(getEvents(oauth2Client, item.id, item.backgroundColor));
}
}
});
Or, if you want any email address to pass, use a regular expression, something like:
getList(oauth2Client).then(items => {
const emailRe = /^\w+@[a-z0-9]\.[a-z]+$/i;
for (const item of items) {
if (item.selected && emailRe.test(item.id)) {
promiseArray.push(getEvents(oauth2Client, item.id, item.backgroundColor));
}
}
});
(if you want to be even more rigorous, see the regex here)
itemsan array, and ispromiseArrayempty at the beginning? (if so, the code can be made prettier)