#javascript #typescript
Вопрос:
[
{
"_id": "615d40a21503e000147d4e97",
"zone": "A",
"country": "India",
"operator_alias": "Idea",
"network_code": "2590",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.653Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e98",
"zone": "A",
"country": "India",
"operator_alias": "Idea",
"network_code": "2591",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e99",
"zone": "A",
"country": "India",
"operator_alias": "Idea",
"network_code": "2592",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e9a",
"zone": "A",
"country": "India",
"operator_alias": "Idea",
"network_code": "2593",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e9b",
"zone": "A",
"country": "India",
"operator_alias": "Airtel",
"network_code": "2594",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e9c",
"zone": "A",
"country": "India",
"operator_alias": "Airtel",
"network_code": "2595",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e9d",
"zone": "A",
"country": "India",
"operator_alias": "Airtel",
"network_code": "2596",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e9e",
"zone": "A",
"country": "India",
"operator_alias": "Jio",
"network_code": "2597",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4e9f",
"zone": "A",
"country": "India",
"operator_alias": "Jio",
"network_code": "2598",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea0",
"zone": "A",
"country": "India",
"operator_alias": "Jio",
"network_code": "2599",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea1",
"zone": "A",
"country": "China",
"operator_alias": "Idea",
"network_code": "2580",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.654Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea2",
"zone": "A",
"country": "China",
"operator_alias": "Idea",
"network_code": "2581",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.655Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea3",
"zone": "A",
"country": "China",
"operator_alias": "Airtel",
"network_code": "2582",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.655Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea4",
"zone": "A",
"country": "China",
"operator_alias": "Airtel",
"network_code": "2583",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.655Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea5",
"zone": "A",
"country": "China",
"operator_alias": "Jio",
"network_code": "2584",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.655Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea6",
"zone": "A",
"country": "China",
"operator_alias": "Jio",
"network_code": "2585",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.655Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea7",
"zone": "A",
"country": "France",
"operator_alias": "Idea",
"network_code": "2586",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.655Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea8",
"zone": "A",
"country": "France",
"operator_alias": "Idea",
"network_code": "2587",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.656Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ea9",
"zone": "A",
"country": "France",
"operator_alias": "Airtel",
"network_code": "2588",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.656Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eaa",
"zone": "A",
"country": "France",
"operator_alias": "Airtel",
"network_code": "2589",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.656Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eab",
"zone": "A",
"country": "France",
"operator_alias": "Jio",
"network_code": "2570",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.656Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eac",
"zone": "A",
"country": "France",
"operator_alias": "Jio",
"network_code": "2571",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.657Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ead",
"zone": "B",
"country": "India",
"operator_alias": "Idea",
"network_code": "2572",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.657Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eae",
"zone": "B",
"country": "India",
"operator_alias": "Idea",
"network_code": "2573",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.657Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eaf",
"zone": "B",
"country": "India",
"operator_alias": "Idea",
"network_code": "2574",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.657Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb0",
"zone": "B",
"country": "China",
"operator_alias": "Airtel",
"network_code": "2575",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.657Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb1",
"zone": "B",
"country": "China",
"operator_alias": "Airtel",
"network_code": "2576",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.657Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb2",
"zone": "B",
"country": "China",
"operator_alias": "Airtel",
"network_code": "2577",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.657Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb3",
"zone": "B",
"country": "India",
"operator_alias": "Airtel",
"network_code": "2578",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.658Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb4",
"zone": "B",
"country": "India",
"operator_alias": "Jio",
"network_code": "2579",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.658Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb5",
"zone": "B",
"country": "India",
"operator_alias": "Jio",
"network_code": "2560",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.658Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb6",
"zone": "B",
"country": "India",
"operator_alias": "Jio",
"network_code": "2561",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.658Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb7",
"zone": "B",
"country": "China",
"operator_alias": "Idea",
"network_code": "2562",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.658Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb8",
"zone": "B",
"country": "China",
"operator_alias": "Idea",
"network_code": "2563",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.658Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eb9",
"zone": "C",
"country": "India",
"operator_alias": "Idea",
"network_code": "2564",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.658Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4eba",
"zone": "C",
"country": "India",
"operator_alias": "Idea",
"network_code": "2565",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.659Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ebb",
"zone": "C",
"country": "India",
"operator_alias": "Idea",
"network_code": "2566",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.659Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ebc",
"zone": "C",
"country": "India",
"operator_alias": "Airtel",
"network_code": "2567",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.659Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ebd",
"zone": "C",
"country": "India",
"operator_alias": "Airtel",
"network_code": "2568",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.659Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ebe",
"zone": "C",
"country": "India",
"operator_alias": "Jio",
"network_code": "2569",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.659Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ebf",
"zone": "C",
"country": "China",
"operator_alias": "Idea",
"network_code": "2550",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.659Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec0",
"zone": "C",
"country": "China",
"operator_alias": "Idea",
"network_code": "2551",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.659Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec1",
"zone": "C",
"country": "China",
"operator_alias": "Airtel",
"network_code": "2552",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.660Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec2",
"zone": "C",
"country": "China",
"operator_alias": "Airtel",
"network_code": "2553",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.660Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec3",
"zone": "C",
"country": "China",
"operator_alias": "Jio",
"network_code": "2554",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.660Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec4",
"zone": "C",
"country": "China",
"operator_alias": "Jio",
"network_code": "2555",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.660Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec5",
"zone": "C",
"country": "Usa",
"operator_alias": "Idea",
"network_code": "2556",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.660Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec6",
"zone": "C",
"country": "Usa",
"operator_alias": "Idea",
"network_code": "2557",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.660Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec7",
"zone": "C",
"country": "Usa",
"operator_alias": "Airtel",
"network_code": "2558",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.660Z",
"__v": 0
},
{
"_id": "615d40a21503e000147d4ec8",
"zone": "C",
"country": "Usa",
"operator_alias": "Airtel",
"network_code": "2559",
"increment_type": "KB",
"network_operator": "615d40a21503e000147d4e96",
"network_category": "M2M",
"updated_at": "2021-10-06T06:22:26.661Z",
"__v": 0
}
];
Это мой массив объектов, Поступающих Из Бэкенда. Мне нужно перестроить или структурировать это, преобразованное в формат ниже
[
"zone":"A",
"Zone_Price":"0",
"Active":"true",
"countries":[
{
"country_name":"India",
"active":"true",
"
- Элемент списка
operators":[
{
"operator_name":"Idea",
"active":"true",
"operator_code":[
{
"operator_code":"2591",
"active":"true"
}
]
}
]
}
]
];
Мне нужно сгруппировать все зоны без дубликатов, предположим, что зона 'A'
имеет несколько стран, все страны перечислены, если страна без дублирования, внутри этой страны есть несколько операторов, которые должны быть перечислены, внутри этих операторов перечислены несколько кодов
Комментарии:
1. Все, что вам нужно, это использовать
Array
функции .map() и .filter (). Ты пробовал?2. да, я пытался, но не смог найти формат exacat
Ответ №1:
Вы должны быть в состоянии получить желаемый результат , используя Array.reduce()
, мы будем использовать массив объектов зоны в качестве накопителя, затем заполнять страны, затем операторов:
let input = [ { "_id": "615d40a21503e000147d4e97", "zone": "A", "country": "India", "operator_alias": "Idea", "network_code": "2590", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.653Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e98", "zone": "A", "country": "India", "operator_alias": "Idea", "network_code": "2591", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e99", "zone": "A", "country": "India", "operator_alias": "Idea", "network_code": "2592", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e9a", "zone": "A", "country": "India", "operator_alias": "Idea", "network_code": "2593", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e9b", "zone": "A", "country": "India", "operator_alias": "Airtel", "network_code": "2594", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e9c", "zone": "A", "country": "India", "operator_alias": "Airtel", "network_code": "2595", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e9d", "zone": "A", "country": "India", "operator_alias": "Airtel", "network_code": "2596", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e9e", "zone": "A", "country": "India", "operator_alias": "Jio", "network_code": "2597", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4e9f", "zone": "A", "country": "India", "operator_alias": "Jio", "network_code": "2598", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea0", "zone": "A", "country": "India", "operator_alias": "Jio", "network_code": "2599", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea1", "zone": "A", "country": "China", "operator_alias": "Idea", "network_code": "2580", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.654Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea2", "zone": "A", "country": "China", "operator_alias": "Idea", "network_code": "2581", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.655Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea3", "zone": "A", "country": "China", "operator_alias": "Airtel", "network_code": "2582", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.655Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea4", "zone": "A", "country": "China", "operator_alias": "Airtel", "network_code": "2583", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.655Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea5", "zone": "A", "country": "China", "operator_alias": "Jio", "network_code": "2584", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.655Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea6", "zone": "A", "country": "China", "operator_alias": "Jio", "network_code": "2585", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.655Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea7", "zone": "A", "country": "France", "operator_alias": "Idea", "network_code": "2586", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.655Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea8", "zone": "A", "country": "France", "operator_alias": "Idea", "network_code": "2587", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.656Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ea9", "zone": "A", "country": "France", "operator_alias": "Airtel", "network_code": "2588", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.656Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eaa", "zone": "A", "country": "France", "operator_alias": "Airtel", "network_code": "2589", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.656Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eab", "zone": "A", "country": "France", "operator_alias": "Jio", "network_code": "2570", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.656Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eac", "zone": "A", "country": "France", "operator_alias": "Jio", "network_code": "2571", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.657Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ead", "zone": "B", "country": "India", "operator_alias": "Idea", "network_code": "2572", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.657Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eae", "zone": "B", "country": "India", "operator_alias": "Idea", "network_code": "2573", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.657Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eaf", "zone": "B", "country": "India", "operator_alias": "Idea", "network_code": "2574", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.657Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb0", "zone": "B", "country": "China", "operator_alias": "Airtel", "network_code": "2575", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.657Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb1", "zone": "B", "country": "China", "operator_alias": "Airtel", "network_code": "2576", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.657Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb2", "zone": "B", "country": "China", "operator_alias": "Airtel", "network_code": "2577", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.657Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb3", "zone": "B", "country": "India", "operator_alias": "Airtel", "network_code": "2578", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.658Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb4", "zone": "B", "country": "India", "operator_alias": "Jio", "network_code": "2579", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.658Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb5", "zone": "B", "country": "India", "operator_alias": "Jio", "network_code": "2560", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.658Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb6", "zone": "B", "country": "India", "operator_alias": "Jio", "network_code": "2561", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.658Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb7", "zone": "B", "country": "China", "operator_alias": "Idea", "network_code": "2562", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.658Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb8", "zone": "B", "country": "China", "operator_alias": "Idea", "network_code": "2563", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.658Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eb9", "zone": "C", "country": "India", "operator_alias": "Idea", "network_code": "2564", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.658Z", "__v": 0 }, { "_id": "615d40a21503e000147d4eba", "zone": "C", "country": "India", "operator_alias": "Idea", "network_code": "2565", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.659Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ebb", "zone": "C", "country": "India", "operator_alias": "Idea", "network_code": "2566", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.659Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ebc", "zone": "C", "country": "India", "operator_alias": "Airtel", "network_code": "2567", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.659Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ebd", "zone": "C", "country": "India", "operator_alias": "Airtel", "network_code": "2568", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.659Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ebe", "zone": "C", "country": "India", "operator_alias": "Jio", "network_code": "2569", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.659Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ebf", "zone": "C", "country": "China", "operator_alias": "Idea", "network_code": "2550", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.659Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec0", "zone": "C", "country": "China", "operator_alias": "Idea", "network_code": "2551", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.659Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec1", "zone": "C", "country": "China", "operator_alias": "Airtel", "network_code": "2552", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.660Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec2", "zone": "C", "country": "China", "operator_alias": "Airtel", "network_code": "2553", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.660Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec3", "zone": "C", "country": "China", "operator_alias": "Jio", "network_code": "2554", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.660Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec4", "zone": "C", "country": "China", "operator_alias": "Jio", "network_code": "2555", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.660Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec5", "zone": "C", "country": "Usa", "operator_alias": "Idea", "network_code": "2556", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.660Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec6", "zone": "C", "country": "Usa", "operator_alias": "Idea", "network_code": "2557", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.660Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec7", "zone": "C", "country": "Usa", "operator_alias": "Airtel", "network_code": "2558", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.660Z", "__v": 0 }, { "_id": "615d40a21503e000147d4ec8", "zone": "C", "country": "Usa", "operator_alias": "Airtel", "network_code": "2559", "increment_type": "KB", "network_operator": "615d40a21503e000147d4e96", "network_category": "M2M", "updated_at": "2021-10-06T06:22:26.661Z", "__v": 0 } ];
const result = input.reduce((acc, { _id, zone, country, operator_alias, network_code }) => {
if (!acc.find(el => el.zone === zone)) {
acc.push( { zone, Zone_Price: '0', Active: true, countries: [] })
}
let zoneObj = acc.find(el => el.zone === zone);
if (!zoneObj.countries.find(el => el.country_name === country)) {
zoneObj.countries.push( { country_name: country, active: true, operators: [] })
}
let countryObj = zoneObj.countries.find(el => el.country_name === country);
if (!countryObj.operators.find(el => el.operator_name === operator_alias)) {
countryObj.operators.push( { operator_name: operator_alias, network_codes: [], active: true })
}
let operatorObj = countryObj.operators.find(el => el.operator_name === operator_alias);
if (!operatorObj.network_codes.find(net => net.code === network_code)) {
operatorObj.network_codes.push( { _id, network_code })
}
return acc;
}, []);
console.log(result)
.as-console-wrapper { max-height: 100% !important; top: 0; }
Комментарии:
1. не могли бы вы, пожалуйста, обновить способ передачи сетевого кода внутри операторов в виде массива объектов «operatos»:[ «оператор»:»Идея», «коды»: [{«код»: «2590»}]]
2. Конечно, я обновил ответ..
3. привет, здесь я хочу, чтобы у идеи оператора было несколько кодов, чтобы весь сетевой код в идее был указан как массив объектов
4. Ага, да, понятно, я обновил, чтобы включить массив сетевых кодов для каждого оператора..
5. привет, можно добавить _id внутри массива сетевых кодов каждого из них?
Ответ №2:
Таким образом, это не приведет к точному формату, который вы описали, но должно помочь вам на вашем пути.
const raw = [{_id: "615d40a21503e000147d4e97",zone: "A",country: "India",operator_alias: "Idea",network_code: "2590",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.653Z",__v: 0},{_id: "615d40a21503e000147d4e98",zone: "A",country: "India",operator_alias: "Idea",network_code: "2591",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4e99",zone: "A",country: "India",operator_alias: "Idea",network_code: "2592",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4e9a",zone: "A",country: "India",operator_alias: "Idea",network_code: "2593",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4e9b",zone: "A",country: "India",operator_alias: "Airtel",network_code: "2594",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4e9c",zone: "A",country: "India",operator_alias: "Airtel",network_code: "2595",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4e9d",zone: "A",country: "India",operator_alias: "Airtel",network_code: "2596",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4e9e",zone: "A",country: "India",operator_alias: "Jio",network_code: "2597",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4e9f",zone: "A",country: "India",operator_alias: "Jio",network_code: "2598",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4ea0",zone: "A",country: "India",operator_alias: "Jio",network_code: "2599",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4ea1",zone: "A",country: "China",operator_alias: "Idea",network_code: "2580",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.654Z",__v: 0},{_id: "615d40a21503e000147d4ea2",zone: "A",country: "China",operator_alias: "Idea",network_code: "2581",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.655Z",__v: 0},{_id: "615d40a21503e000147d4ea3",zone: "A",country: "China",operator_alias: "Airtel",network_code: "2582",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.655Z",__v: 0},{_id: "615d40a21503e000147d4ea4",zone: "A",country: "China",operator_alias: "Airtel",network_code: "2583",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.655Z",__v: 0},{_id: "615d40a21503e000147d4ea5",zone: "A",country: "China",operator_alias: "Jio",network_code: "2584",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.655Z",__v: 0},{_id: "615d40a21503e000147d4ea6",zone: "A",country: "China",operator_alias: "Jio",network_code: "2585",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.655Z",__v: 0},{_id: "615d40a21503e000147d4ea7",zone: "A",country: "France",operator_alias: "Idea",network_code: "2586",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.655Z",__v: 0},{_id: "615d40a21503e000147d4ea8",zone: "A",country: "France",operator_alias: "Idea",network_code: "2587",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.656Z",__v: 0},{_id: "615d40a21503e000147d4ea9",zone: "A",country: "France",operator_alias: "Airtel",network_code: "2588",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.656Z",__v: 0},{_id: "615d40a21503e000147d4eaa",zone: "A",country: "France",operator_alias: "Airtel",network_code: "2589",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.656Z",__v: 0},{_id: "615d40a21503e000147d4eab",zone: "A",country: "France",operator_alias: "Jio",network_code: "2570",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.656Z",__v: 0},{_id: "615d40a21503e000147d4eac",zone: "A",country: "France",operator_alias: "Jio",network_code: "2571",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.657Z",__v: 0},{_id: "615d40a21503e000147d4ead",zone: "B",country: "India",operator_alias: "Idea",network_code: "2572",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.657Z",__v: 0},{_id: "615d40a21503e000147d4eae",zone: "B",country: "India",operator_alias: "Idea",network_code: "2573",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.657Z",__v: 0},{_id: "615d40a21503e000147d4eaf",zone: "B",country: "India",operator_alias: "Idea",network_code: "2574",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.657Z",__v: 0},{_id: "615d40a21503e000147d4eb0",zone: "B",country: "China",operator_alias: "Airtel",network_code: "2575",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.657Z",__v: 0},{_id: "615d40a21503e000147d4eb1",zone: "B",country: "China",operator_alias: "Airtel",network_code: "2576",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.657Z",__v: 0},{_id: "615d40a21503e000147d4eb2",zone: "B",country: "China",operator_alias: "Airtel",network_code: "2577",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.657Z",__v: 0},{_id: "615d40a21503e000147d4eb3",zone: "B",country: "India",operator_alias: "Airtel",network_code: "2578",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.658Z",__v: 0},{_id: "615d40a21503e000147d4eb4",zone: "B",country: "India",operator_alias: "Jio",network_code: "2579",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.658Z",__v: 0},{_id: "615d40a21503e000147d4eb5",zone: "B",country: "India",operator_alias: "Jio",network_code: "2560",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.658Z",__v: 0},{_id: "615d40a21503e000147d4eb6",zone: "B",country: "India",operator_alias: "Jio",network_code: "2561",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.658Z",__v: 0},{_id: "615d40a21503e000147d4eb7",zone: "B",country: "China",operator_alias: "Idea",network_code: "2562",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.658Z",__v: 0},{_id: "615d40a21503e000147d4eb8",zone: "B",country: "China",operator_alias: "Idea",network_code: "2563",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.658Z",__v: 0},{_id: "615d40a21503e000147d4eb9",zone: "C",country: "India",operator_alias: "Idea",network_code: "2564",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.658Z",__v: 0},{_id: "615d40a21503e000147d4eba",zone: "C",country: "India",operator_alias: "Idea",network_code: "2565",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.659Z",__v: 0},{_id: "615d40a21503e000147d4ebb",zone: "C",country: "India",operator_alias: "Idea",network_code: "2566",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.659Z",__v: 0},{_id: "615d40a21503e000147d4ebc",zone: "C",country: "India",operator_alias: "Airtel",network_code: "2567",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.659Z",__v: 0},{_id: "615d40a21503e000147d4ebd",zone: "C",country: "India",operator_alias: "Airtel",network_code: "2568",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.659Z",__v: 0},{_id: "615d40a21503e000147d4ebe",zone: "C",country: "India",operator_alias: "Jio",network_code: "2569",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.659Z",__v: 0},{_id: "615d40a21503e000147d4ebf",zone: "C",country: "China",operator_alias: "Idea",network_code: "2550",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.659Z",__v: 0},{_id: "615d40a21503e000147d4ec0",zone: "C",country: "China",operator_alias: "Idea",network_code: "2551",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.659Z",__v: 0},{_id: "615d40a21503e000147d4ec1",zone: "C",country: "China",operator_alias: "Airtel",network_code: "2552",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.660Z",__v: 0},{_id: "615d40a21503e000147d4ec2",zone: "C",country: "China",operator_alias: "Airtel",network_code: "2553",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.660Z",__v: 0},{_id: "615d40a21503e000147d4ec3",zone: "C",country: "China",operator_alias: "Jio",network_code: "2554",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.660Z",__v: 0},{_id: "615d40a21503e000147d4ec4",zone: "C",country: "China",operator_alias: "Jio",network_code: "2555",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.660Z",__v: 0},{_id: "615d40a21503e000147d4ec5",zone: "C",country: "Usa",operator_alias: "Idea",network_code: "2556",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.660Z",__v: 0},{_id: "615d40a21503e000147d4ec6",zone: "C",country: "Usa",operator_alias: "Idea",network_code: "2557",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.660Z",__v: 0},{_id: "615d40a21503e000147d4ec7",zone: "C",country: "Usa",operator_alias: "Airtel",network_code: "2558",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.660Z",__v: 0},{_id: "615d40a21503e000147d4ec8",zone: "C",country: "Usa",operator_alias: "Airtel",network_code: "2559",increment_type: "KB",network_operator: "615d40a21503e000147d4e96",network_category: "M2M",updated_at: "2021-10-06T06:22:26.661Z",__v: 0}];
const zoneMap = new Map();
for (const entry of raw) {
const zone = zoneMap.get(entry.zone) ?? {
zone: entry.zone,
countries: new Map()
};
zoneMap.set(entry.zone, zone);
const country = zone.countries.get(zone.country) ?? {
country: entry.country,
operators: new Map()
};
zone.countries.set(entry.country, country);
const operator = country.operators.get(zone.operator_alias) ?? {
operator: entry.operator_alias
};
country.operators.set(entry.operator_alias, operator);
}
const processed = Array.from(zoneMap.values()).map((o) => ({
zone: o.zone,
countries: Array.from(o.countries.values()).map((c) => ({
country: c.country,
operators: Array.from(c.operators.values())
}))
}));
console.log(processed);