I have an object that is a collection of index numbers. Under each number there are two properties and an array. I am trying to write a function that will accept arguments of the index number, the property to be updated, and the value. So far I can’t figure out how to access the array.
var myObject =
{
"0001":
{
"prop1": ""
"prop2": ""
"prop3": []
}
To access prop1 and prop2 I was able to just use an if statement:
if (prop == "prop1 ")
{
collection[id].prop1 = value;
}
else if(prop == "prop2")
{
collection[id].prop2 = value;
}
When I tried to get to the array it fell apart. I tried a few things by the most logical one seemed to be:
if(prop == "prop3")
{
collection[id].prop3.push(value);
}
Where am I going wrong here?