0
I need to clone my Objects array so that the Undefined properties do not overwrite an existing property.
const myArray = [
{
"tecnico": "INS-MAN-RENAN M/RENAN C",
"horas": "08:30:00",
"2021-04-18": "21.94502"
},
{
"tecnico": "INS-MAN-RENAN M/RENAN C",
"horas": "08:30:00",
"2021-04-18": ""
},
{
"tecnico": "INS-MAN-RENAN M/RENAN C",
"horas": "08:30:00",
"2021-04-23": ""
},
]
console.log(Object.assign({}, ...myArray));
I need to get the following result:
{
"tecnico": "INS-MAN-RENAN M/RENAN C",
"horas": "08:30:00",
"2021-04-18": "21.94502",
"2021-04-23": ""
}
It is not cloning what you seek. Wouldn’t it be reducing to an element? If it will even reduce what the criteria for choosing the data in the case of keys already populated with different values. Example: If there are two objects in the array whose key hour are like this
{"horas": "08:30:00"}, {"horas": "12:00:00"}
?– Augusto Vasques
It would clone because the repeated keys will be reduced to an object as in the above case and the ones that are not will be inserted in the same object ... the problem is when you find an equal key with an undefined value and end up overwriting the previous value, as in the case of the date 2021-04-18
– Danilo Dias
I repeat is not cloning is reducing, see the example https://ideone.com/eSk8Rm
– Augusto Vasques