Insert an element into an array that contains an object

1
Hello, I would like to know how to insert an element into an object in an array, in this case, when I add it with the code below, the element is inserted as another index:

 this.array = [];
 this.array.push(email);
 this.array.push({ Mensagem: res.data[0].Mensagem });

The feedback I get is this one:

[
  {
    "CodigoPostagem": 25,
    "DataMensagem": "2017-06-28T14:35:00",
    "Emitente": "Item",
    "Titulo": "Mensagem número 25",
    "Visualizado": false
  },
  {
    "Mensagem": "Teste"
  }
]

The "email" has the above item, I just wanted to insert the return of an api inside that object.

Thank you in advance!

    
asked by anonymous 29.06.2017 / 23:44

1 answer

3

You can only assign before doing push :

this.array = [];
email.mensagem = res.data[0].Mensagem;
this.array.push(email);
    
29.06.2017 / 23:47