For updateRecords(collection, 5439, "tracks", "Take a Chance on Me").
if(object['5439']['tracks'] != 'tracks' && 'Take a Chance on Me' != '') {
object['5439']['tracks'] = 'Take a Chance on Me';
}
That is saying:
IF THE VALUE OF collection[“5439”][“tracks”] IS NOT “tracks” AND THE STRING “Take a Chance on Me” IS NOT an empty string ASSIGN “Take a Chance on Me” TO collection[“5439”][“tracks”]
So that condition is true, the property is undefined, not the string "tracks". So the first condition you have will always assign object[id][prop] = value. So you end up with:
{
// ...snip
5439: {
albumTitle: 'ABBA Gold',
tracks: 'Take A Chance on Me'
},
};
Then the function will error, because the second condition after that says:
if('tracks' === 'tracks' && value != ''){
object['5439][prop].push(value);
}
So
IF THE VALUE OF THE STRING “tracks” IS “tracks” AND THE VALUE OF THE STRING “Take a Chance on Me” IS NOT AN EMPTY STRING, push THE STRING “Take a Chance on Me” TO collection[“5439”][“tracks”]
You can’t push on a string, so this errors.
You need to fix the first condition, you need to check what the variables passed into the function are, not what you’re currently doing. Once you fix that, you need to use else if otherwise the code will just run every condition that is true – you’re just doing one operation after another (if you leave it as-is, the third if block will run immediately after the second if block)