How to transform an array of a SINGLE object?

-1

My question is, how can I make an array that has 3 objects to become a single object? As the print below, the matrix is bringing me 3 objects, however I need to assemble a single object with the value of each array, I already researched something like reduce, but could not succeed. Here is my code:

       //"ITEMS" é um FirebaseListObservable que transformo em um array
       //javascript

       //dadosPontoFuncionario é o meu array javascript, que está retornando
       //o que está no console, é ele que preciso que vire um único objeto

       this.items.subscribe( data => {
         this.dadosPontoFuncionario = data;
         console.log(this.dadosPontoFuncionario);
       })

    
asked by anonymous 19.12.2018 / 19:47

1 answer

0

I do not know if I understand correctly, but I'll try ...

If it's what I'm imagining,

const arrayObject = [
{nome:'Objeto um'},
{teste:'Objeto dois'},
{nome:'Objeto tres'}
]

console.log(arrayObject.reduce((a,b)=>({...a, ...b})))

You can do a reduce, the problem is that if the objects have keys with the same name it will be worth the value of the key of the last object found ..

    
19.12.2018 / 20:14