I want to reduce the array with only the subject being present in the new object.
array = [{
subject: "maths",
credits: 3
},
{
subject: "chemistry",
credits: 2,
lab: {
lab: "chemistry_lab",
lab_credits: 1,
},
}
]
the new object is reformatted and its values are assigned as strings. What's the best way to achieve this
const subject = {
maths: "",
chemistry: "",
chemistry_lab: "",
};
Here's how I tried this but it returns an array of objects, but I want this to be a single object as above
const sub = array.map((op) => {
const container = {};
container[op.subject] = "";
return container;
});
"chemistry_lab"in this mapping? It's not asubject. What are the rules for this mapping?