I'm currently working with a JSON object in Angular and I need to dynamically add values that the user enters. Despite searching extensively, I haven't found a straightforward method to achieve this. I simply want to understand how to append key-value pairs to the JSON object.
Below is the TypeScript code sample:
people: any[]=[{
"name": "jacob",
"age": 22 },
{
"name": "sruthi",
"age": 29 }
]
My goal is to update the JSON object with new names and ages as users input them.
The corresponding HTML code snippet is shown below:
<input type="text" class="frm-control" placeholder="Enter Name" (change)="insert_name($event.target.value)">
<input type="text" class="frm-control" placeholder="Enter Age" (change)="insert_age($event.target.value)">
<br>
<button type="button" class="btn btn-success" style="margin-top:10px;" (click)="submit()">Submit</button>