Can't create a new object property using dot

I’m doing freecodecamp’s JS course and there’s a certain exercise I’m stuck with.

Here’s the code:

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'

function updateRecords(records, id, prop, value) {
  if(prop !== 'tracks' && value !== ''){[prop] = value;
  return records;

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

The line "[prop] = value" gives me the error "TypeError: Cannot set properties of undefined ".
I don’t understand this since from what I know this should work. Any help?

Edit: by the way, records[id][prop] does work, which I’m not sure why. id is a given number which represents a property, why can’t I call it with dot notation?

You can only use bracket notation when you have a variable holding the property name. Dot notation can only be used when you have the exact, literal property name.

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