Add a key / value to an object in typescript

1

I have an array object that I want to add a key and value in it.

I tried something like:

this.testeobj//meu objeto
this.testeobj[0].push({oi: 'teste});
    
asked by anonymous 27.10.2018 / 02:12

1 answer

0

You want an array of objects

this.testeobj = [] //seu array de objetos
this.testeobj.push({oi: 'teste});

The push is a property only of the array, it will insert in the last position of your array the past value that in your case is an object.

The example below passing the position is only when you want to put the value in the exact position of the array

this.testeobj[0] = {oi: 'teste};

I hope I have helped

    
27.10.2018 / 05:16