JSFiddle - React, Tailwind, and code Playground

TypeScript

interface IAccountDto
{
    accountId: number;
    accountName: string;

    selected?: boolean; // not in actual DTO, just used in UI
}

interface IAreaDto
{
    areaName: string;
    accounts: IAccountDto[];
}



class Something {

   	message = "Hello";
   
	areas: IAreaDto[] = [
            {
                areaName: "Philippines",
                accounts: [
                    {
                        accountId  : 168,
                        accountName: "Account 168",
                        selected: true
                    },
                    {
                        accountId  : 169,
                        accountName: "Account 169",
                        selected: true
                    },
                ]
            },
            {
                areaName: "China",
                accounts: [
                    {
                        accountId  : 170,
                        accountName: "Account 170"
                    },
                    {
                        accountId  : 171,
                        accountName: "Account 171",
                        selected: true
                    },
                ]
            },


        ];   
   
   
   getResult(): number[] {
       let result = 
            this.areas.map(ar => ar.accounts)
            .reduce((a,b) => a.concat(b), [])
            .filter(ac => ac.selected)
            .map(ac => ac.accountId)
            
       return result;

   }
}



let s = new Something();

let x = JSON.stringify(s.getResult());

document.body.innerHTML = x;