I have an array of objects with named keys as follows:
Array1 [
{
'town1': 'London', // string
'town2': 'Paris', // string
'distance': 123456, // number
},
{
'town1': 'Seoul', // string
'town2': 'Tokio', // string
'distance': 654321, // number
},
{},{},... // Objects with same properties
]
Note that there might be objects without these keys. They should be skipped.
Having all this I want to create a new Array of arrays with 2 objects inside with the following rigid structure:
Array2 [
[{ name: 'town1', value: 'distance'}, { name: 'town2'}],
[{ name: 'town1', value: 'distance'}, { name: 'town2'}],
[{...}, {...}], // All other objects with existing town1-town2-distance
]
How one could achieve it in the most efficient and fast way?

[{ name: 'London', value: 123456 }, { name: 'Paris' }]?