Basic JavaScript - Record Collection

Tell us what’s happening:

To access the value of a key in this object, you will use bracket notation: records[id][prop] . dont understand this statement

for example
if (value === “”) {
delete records[id][prop];
wouldnt you just use record[prop] in this case why add the [id]

Your code so far

// Setup
const recordCollection = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: 'Bon Jovi',
    tracks: ['Let It Rock', 'You Give Love a Bad Name']
  },
  2468: {
    albumTitle: '1999',
    artist: 'Prince',
    tracks: ['1999', 'Little Red Corvette']
  },
  1245: {
    artist: 'Robert Palmer',
    tracks: []
  },
  5439: {
    albumTitle: 'ABBA Gold'
  }
};

// Only change code below this line
function updateRecords(records, id, prop, value) {
  return records;
}if (value === "") {
    delete records[id][prop];

hello guys,kind of a dumb question but why would you use records[id][prop]; and not records[prop], 
i saw this on tips [To access the value of a key in this object, you will use bracket notation: records[id][prop]. having a hard time understanding this please help

updateRecords(recordCollection, 5439, 'artist', 'ABBA');

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Let’s say that id is 2548.

What does record[id] return?

If you wanted to know the artist for this id, how would you access that with JS?

thank you, made sense after a while need more grinding

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.