How can I format an object with a basic structure to a complex structure containing arrays in an efficient way?
Sample input:
const obj = {
OBJ1: "obj1",
OBJ2: "obj2",
}
const mapper = {
"obj1": "Object1"
"obj2": "Object2"
}
Expected output:
const converted = {
obj1 : { name: "Object1", arr: [] }
obj2: { name: "Object2", arr: [] }
}
I need to run a map on key value pairs of object obj
, and to that key I need to add a property called name
with its value from another object mapper
and then add arr
array as another property to this key
I tried:
const convert = () => {
const newObj = {};
Object.entries(columnsToInclude).map(
([key, value]) => (newObj[key] = { name: mapper[value], arr: [] })
);
};