0

Say I have an object like this:

   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'
  }
};

I know I can print a single property like this:

console.log (recordCollection[2548]['artist'];

And I wonder whether it is possible to do something like this:

console.log (recordCollection[2548]['artist', 'tracks'];

How would I print both artist and tracks?

noam gaash
  • 337
  • 2
  • 13
  • This is like you'd have red and green apple on a table, you can take the red apple and eat it, but there's no way to take the green apple? – Teemu Nov 16 '21 at 06:33

1 Answers1

0

It should be: recordCollection[2548]['artist']

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'
  }
};
console.log(recordCollection[2548]['artist']);
kiner_shah
  • 3,939
  • 7
  • 23
  • 37