Q:

How to loop through all JSON objects?

I'm trying to add multiple Objects and later to display them all. How would I do this? Every method I googled just uses For-In/For and iterate through characters and I only see the last added object...
for(var i = 0; i < forms.length; i++) 
{
        alert(forms[i].id + " " + 10 + " " + forms[i].value);
        var aObj = new A(forms[i].id, 10, forms[i].value);
        var obj = JSON.stringify(aObj);
}

var str = "";
for(var i = 0; i < jObj.length; i++) 
{
    str += jObj[i]; 
}

alert(str);

Only solution I can come up is to create an array and store them all there?

A:

You are reinitalizing the variables aObj and obj and that is causing them to be overwritten every time the loop is executed. They should be arrays with the iteration specified.
var aObj;
var obj = [];
var str = "";

for(var i = 0; i < forms.length; i++) 
{
        alert(forms[i].id + " " + 10 + " " + forms[i].value);
        aObj = new A(forms[i].id, 10, forms[i].value);
        obj[i] = JSON.stringify(aObj);
}

for(var i = 0; i < jObj.length; i++) 
{
    str += jObj[i]; 
}

alert(str);

