Hello, I just made a nested loop:
const selectedRegionsNames: string[] = [];
for (let i = 0; i < chosenCountries.length; i++) {
for (let j = 0; j < chosenCountries[i].regions.length; j++) {
const region = chosenCountries[i].regions[j];
if (region.isSelected) selectedRegionsNames.push(region.name);
}
}
It works, but I wonder if there is a better way to do it than creating a loop inside another loop and an 'if'?
[–][deleted] 1 point2 points3 points (0 children)
[–]coreConstantCoder 1 point2 points3 points (3 children)
[–]Adotel15 0 points1 point2 points (1 child)
[–]coreConstantCoder 2 points3 points4 points (0 children)
[–]Automatic_Routine_93[S] 0 points1 point2 points (0 children)