Skip to content
Advertisement

map through an object and fill another object

I am trying to map through the data.scales array of objects and display the values in the obj createvalues array as shown in the output. I cannot quite figure this out. I have to make sure I do not delete the values existing in the createValues array

const obj = {
projecd: 0,
grd: 0,
crea: [
  {
    field: 1,
    value: "cool"
  },
  {
    field: 11,
    value: "cl"
  },
  {
    field: 11,
    value: "cool"
  }
]
};

const data = {
scs:[
  {
    SleId:15,
    Value:"LOW"
  },
   {
    eId:105,
    Value:"LOW"
  }  
] 
};
const result = Object.entries(data.ses).map(([key, value]) => ({
field: data.sces.value,
value: data.scas.value
}));

console.log(result)
obj.createues=

The output expected is this one :

const output = {
projecd: 0,
gri: 0,
createues: [
   {
    field: 1111,
    value: "cool"
  },
  {
    field: 141,
    value: "cl"
  },
  {
    field: 11,
    value: "cool"
  }
  {
    field: 15,
    value: "LOW"
  },
  {
  field: 165,
  value: "LOW"
}
]
};

Advertisement

Answer

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement