I\'d like to have JavaScript objects within another JavaScript object as such:
Issues:
- {\"ID\" : \"1\", \"Name\" : \"Missing Documentation\", \"Notes\"
var jsonIssues = []; // new Array
jsonIssues.push( { ID:1, "Name":"whatever" } );
// "push" some more here
As my first object is a native javascript object (used like a list of objects), push
didn't work in my escenario, but I resolved it by adding new key as following:
MyObjList['newKey'] = obj;
In addition to this, may be usefull to know how to delete same object inserted before:
delete MyObjList['newKey'][id];
Hope it helps someone as it helped me;
// Merge object2 into object1, recursively
$.extend( true, object1, object2 );
// Merge object2 into object1
$.extend( object1, object2 );
https://api.jquery.com/jquery.extend/
jsonIssues = [...jsonIssues,{ID:'3',Name:'name 3',Notes:'NOTES 3'}]
var jsonIssues = [
{ID:'1',Name:'Some name',Notes:'NOTES'},
{ID:'2',Name:'Some name 2',Notes:'NOTES 2'}
];
If you want to add to the array then you can do this
jsonIssues[jsonIssues.length] = {ID:'3',Name:'Some name 3',Notes:'NOTES 3'};
Or you can use the push technique that the other guy posted, which is also good.