How to add new data in JSON with TypeScript and Angular

0

I have a JSON look like this:

[
    {
        "texto": "Eae", 
        "contato": "Luis", 
        "data": "2018-09-25T21:08:00"
    },{
        "texto": "Salve povo", 
        "contato": "Rogerio", 
        "data": "2018-09-25T21:15:00"
    }
]

And an HTML component with a textarea where the user would type the text and missing data such as contact and date are caught dynamically.

How do I add a "message" in JSON so that it looks something like this:

[
    {
        "texto": "Eae", 
        "contato": "Luis", 
        "data": "2018-09-25T21:08:00"
    },{
        "texto": "Salve povo", 
        "contato": "Rogerio", 
        "data": "2018-09-25T21:15:00"
    },{
        "texto": "De boas?", 
        "contato": "Victor", 
        "data": "2018-09-25T21:09:00"
    }
]
    
asked by anonymous 27.09.2018 / 18:46

1 answer

0

Did you try using Array.push ?

It would be something like:

meuArray.push({
    "texto": "De boas?", 
    "contato": "Victor", 
    "data": "2018-09-25T21:09:00"
});

or

var objetoComAsInformacoesDesejadas = {
    "texto": "De boas?", 
    "contato": "Victor", 
    "data": "2018-09-25T21:09:00"
};
meuArray.push(objetoComAsInformacoesDesejadas);
    
27.09.2018 / 18:52