I have this JSON object:
var collection = {
"123":{
"name": "Some Name",
"someArray": [
"value 0",
"value 1"
]
},
"124":{
"name": "Some Name"
},
I have a method that updates and returns the collection like:
function updateCollection(id, property, value){
return collection;
}
Suppose the method call is like this:
updateCollection(124, someArray, "value 3");
How should I update? What I already wrote is:
function updateCollection(id, property, value){
if(collection[id].hasOwnProperty(property)){
collection[id][property].push(value);
}
else{
//need help here
}
return collection;
}
Expected Output after calling method updateCollection(124, someArray, "value 3"); should be:
"124":{ "name": "Some Name", "someArray": [ "value 3", ] }
collection[id] = [value];?updateCollection(124, someArray, "value 3");?