I want to create a new object and assign some properties for each array stored within some json. I have this mostly working except…
for (var i in json) {
a = 0;
a++;
a = new Object();
for (var key in json[i]) {
var Key = key;
var Value = json[i][key];
a[Key] = Value;
}
a.outputProperties();
}
When I output the object properties, everything is undefined.
If I create a single object outside the loop and assign the properties to it, it seems to work OK except that the first set of properties get overwritten with the following. Not sure why I wouldn’t be able to create objects and assign properties inside the loop dynamically.
Dave Smith’s answer was pretty close to what I needed but it didn’t create new objects within the loop. Here’s my updated code that provided the desired result:
Each new object is now stored within an array, theGoods[];
I can now reference that object by writing something like:
theGoods["obj2"].someMethod();