0

I have one table and button. If I click on a button I need to generate table data in JSON format with one new key/value pair (the value is generated dynamically). The JSON I'm getting like this:

[{"id":"3","Test1":"Cartman","Test2":"123"},{"id":"3","Test1":"abc","Test2":"456"}]

I'm expecting JSON like this:

[{"sampledata":"123","id":"3","Test1":"Cartman","Test2":"123"},{"sampledata":"123","id":"3","Test1":"abc","Test2":"456"}]

I tried to add this dynamically but the data is not populated.

Working Stackblitz

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Rajasekhar
  • 2,215
  • 3
  • 23
  • 38
  • Either loop through the array of objects to add the property (as in the marked duplicate), or alternatively instantiate the object with the default property: `jsonData1[index] = { sampledata: '123' };` - https://stackblitz.com/edit/angular-datatables-gitter-eq1l4l?file=app%2Fapp.component.ts – Rory McCrossan Dec 10 '20 at 16:14
  • Also note that you're working with an array of objects, not JSON. This is perhaps why your research didn't give you an appropriate answer – Rory McCrossan Dec 10 '20 at 16:15

0 Answers0