Чего мучаться?
Сначала отфильтровать, потом оптимизировать
let countries = [
{
iso: "ca",
flag: "<svg></svg>"
},
{
iso: "us"
},
{
iso: "an"
}
];
async function optimizeSVG(str) {
return str;
}
async function filterCountries() {
const countriesToIgnore = ['an'];
const filtered = countries.filter(country => !countriesToIgnore.includes(country.iso))
let result = await Promise.all(filtered.map(async (country) => {
let flag = await optimizeSVG(country.flag);
return [country.iso, flag || 'noflag'];
}));
console.log(result);
}
filterCountries();