Record Collection - I don't quite understand it

Hello all. I spent several hours trying to figure out this challenge before looking at the solution, but I’m afraid I still don’t understand it. I went through the explanation and tried to comment out the code so it makes sense to me, but I’m still puzzled by 2 sections (which I’ve marked with ? marks.)

In short, what is the purpose and what is the difference between:
collection[id][prop]=[value];
collection[id][prop] = value;

The entire code for reference:

var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
var collectionCopy = JSON.parse(JSON.stringify(collection));

function updateRecords(id, prop, value) {
  if (prop === "tracks" && value !== "") //Checks that Prop is "Tracks" and Value is not a blank string.
  {
    if(collection[id][prop]) {
      collection[id][prop].push(value); //Adds Value to the Tracks array.
    } else {
    collection[id][prop]=[value]; //Value is updated? to the Tracks array.
    }
   } else if (value !== "") { //Checks if Value is not a blank string.
    collection[id][prop] = value; //Value is updated? to the Tracks array.
  } else {
    delete collection[id][prop]; //Value is a blank string. Ergo removes the Prop from the object.
  }
   // console.log (collection[id][prop]);
  return collection;
}

// Alter values below to test your code
console.log (collection);
updateRecords(5439, "artist", "ABBA");
console.log (collection);

Using bracket and dot notations you can access values nested in an object.
For example,

collection[“2548”][“album”] will return “Slippery When Wet”.
By passing in different values for variables id and prop, you are accessing their corresponding values.

Then they are using = operators to assign values to them or replacing already existing values.

[value]
value

Difference between these two on the right side of equal operators are simply one is in an array and the other isn’t.

1 Like

OH! Okay! The Tracks section of the collection is an array. And we know it’s pointing at the Tracks because of the first If statement. And we know the If/Else statement is pointing at Album or Artist. This lesson is complicated but I think I understand it better now.

So in this case my comments should be:
collection[id][prop]=[value]; //Value is updated to the Tracks array.
and
collection[id][prop] = value; //Value is updated to Album or Artist property.