I have an object like this -
const obj = {
'veh1': 'Car',
'veh2': 'Bicycle',
'veh3': 'Truck',
'wheels1': '4',
'wheels2': '2',
'wheels3': '8'
}
I want an object which have entries mapped like- veh1 to wheels1, veh2 to wheels2, veh3 to wheels3 and so on The resultant object should be like this-
const result = {
'Car': '4',
'Bicycle': '2',
'Truck': '8'
}
I know, we can do it directly like this -
{
[obj.veh1]: obj.wheels1,
[obj.veh2]: obj.wheels2,
[obj.veh3]: obj.wheels3
}
But what will be the better way? The number of entries can be any number 'n'.
How can I attain this through javascript?