ppshein ppshein - 1 year ago 52
AngularJS Question

How to add new json node in javascript

Here is my current json response.


But I want to add new node to above json as follow,

[{"id":1,"name":"Yangon","$$hashKey":"object:170", "township_id": 1, "township_name": "Ahlone"}]

Please help me how to do it. Thanks in advance.

Answer Source

You need to store your response into a variable (it probably already is) and just add whatever key/values you want:


var arr = [{ "id": 1, "name": "Yangon", "$$hashKey": "object:170" }];

arr[0]['township_id'] = 1;
arr[0]['township_name'] = 'Ahlone';



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download