I'd like to have JavaScript objects within another JavaScript object as such:
Issues:
- {"ID" : "1", "Name" : "Missing Documentation", "Notes" : "Issue1 Notes"}
- {"ID" : "2", "Name" : "Software Bug", "Notes" : "Issue2 Notes, blah, blah"}
- {"ID" : "2", "Name" : "System Not Ready", "Notes" : "Issue3 Notes, etc"}
// etc...
So, I'd like "Issues" to hold each of these JavaScript objects, so that I can just say Issues[0].Name, or Issues[2].ID, etc.
I've created the outer Issues JavaScript object:
var jsonIssues = {};
I'm to the point where I need to add a JavaScript object to it, but don't know how. I'd like to be able to say:
Issues<code here>.Name = "Missing Documentation";
Issues<code here>.ID = "1";
Issues<code here>.Notes = "Notes, notes notes";
Is there any way to do this? Thanks.
UPDATE: Per answers given, declared an array, and am pushing JavaScript objects on as needed:
var jsonArray_Issues = new Array();
jsonArray_Issues.push( { "ID" : id, "Name" : name, "Notes" : notes } );
Thanks for the responses.
If you want to add to the array then you can do this
Or you can use the push technique that the other guy posted, which is also good.
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:In addition to this, may be usefull to know how to delete same object inserted before:
Hope it helps someone as it helped me;
// Merge object2 into object1, recursively
// Merge object2 into object1
https://api.jquery.com/jquery.extend/