I have a doubt doing this challenge. When I use .push() in the variable prop instead .tracks I can’t update the collection but if I use the varible in the second case the program is OK. Why does this happen?
switch(prop){
case "tracks":
console.log(prop);
collectionCopy[id].prop.push(value);
console.log(collectionCopy[id].prop);
return "Agregado";
break;
case "artist":
collectionCopy[id].prop = value;
console.log(collectionCopy[id].prop);
return collectionCopy[id].prop;
break;
}
prop is the variable used in the function an it’s referenced to a key called “tracks”. I have a if condiftion to solve if “tracks” not exists
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
}
function updateRecords(id, prop, value) {
//My solution
}
updateRecords(5439, "tracks", "red");