Hello, I don’t understand why this code doesn’t work:
function updateRecords(id, prop, value) { if (value !== "") { if (prop !== "tracks") { collection[id][prop] = value; } else if (collection.hasOwnProperty("tracks") == true) { collection[id].tracks.push(value); } else { collection[id].tracks = [value]; } } else { delete collection[id][prop]; } return collection; }
The only test it fails is " After updateRecords(2468, "tracks", "Free")
, tracks
should have "1999"
as the first element.", it replaces the original tracks array with a new one with “Free” as the only track, I do not understand why since if it already has a tracks array it should just add “Free” to the end because of this bit:
else if (collection.hasOwnProperty("tracks") == true) { collection[id].tracks.push(value)"
Thanks for your attention.
Edit: I don’t know how to indent it correctly, sorry.