I am trying to dynamically add and remove JSON elements from json object. But its not updating in JSON.stringify output.
{
"selected_stores": [
{
"row_0": "3366::1148",
"row_1": "3366"
}
]
}
I am trying to add more elements in it . like row_2 an so but it doesn’t work. after adding new element console.log(obj); logs new element. but output is not updated.
Thanks in advance.
The problem was that the
selected_storesobject is an array with a single element: an object that contains multiple properties. The code however, assumed that the array was an array of multiple objects (one for each row).You’ll probably want to update your JSON structure to this:
If you meant to write the JSON the way you did, all that needed to be done in the code was to make a reference to the
selected_storesfirst array element: the object that contained the row properties:selected_stores_jsonObj.selected_stores[0]['row_' + row_num] = outcheckedStr;http://jsfiddle.net/4TzRC/28/