Сделал версию на array.map
let countries = [
{
iso: "ca",
flag: "<svg></svg>"
},
{
iso: "us"
},
{
iso: "an"
}
];
async function optimizeSVG(str) {
return str;
}
async function filterCountries() {
const countriesToIgnore = ['an'];
let result = await Promise.all(countries.map(async (country) => {
if (!countriesToIgnore.includes(country.iso)) {
let flag = await optimizeSVG(country.flag);
return [country.iso, flag || 'noflag'];
}
}));
result = result.filter(Boolean);
console.log(result);
}
filterCountries();
но можно ли без result = result.filter(Boolean);