I have an array of strings with vehicle names.
a=['car', 'scooter', 'bike'];
I need to generate a array such that each object would have a property color:red
in it
I used array.reduce
for it. This is the code i have written
function getInitialMap(a) {
const vehicleMap = [];
return vehicles.reduce((_vehicleMap, type) => {
_vehicleMap.concat({[type]: {color: red}});
return _vehicleMap;
}, vehicleMap);
}
what I got is:
_vehicleMap = [
0:{car:{color:red}},
1:{scooter:{color:red}},
2:{bike:{color:red}}
]
what I required:
_vehicleMap = [
car:{color:red},
scooter:{color:red},
bike:{color:red},
]
Can someone help in generating array with custom keys here