Record Collection (Help me understand this!)

This is the task:

Given code to modify:


// Setup
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"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  
  return collection;
}

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

Here is a given solution, but i don’t understand a few things:
jsDataCollectionTask

What is the different between:
collection[id][prop]=[value] and collection[id][prop]=value

Link to the challenge:

if (prop === "tracks" && value !== "") { 
  /*if we are working with "tracks" property, then proceed, if not, go to line 11*/
 if (collection[id][prop]) {
    /*if we are working on tracks property and if there is a track property on the object, then proceed, if not go to line 7*/
    collection[id][prop].push(value)
      /*since there already is a "tracks" property, we know that it is an array and push current value to it*/
  } else { /*this block gets executed if there is no "tracks" key on the object*/
      /*so we create an array containing only a current value - [value] - and assign it to the "tracks" key*/
     collection[id][prop] = [value];
  }
} //the rest of the code you have annotated well
  
2 Likes

Now I understand very well…
thanks to you @achere !