// 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;
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
for example in the last line of code ‘artist’ should be equal to ‘ABBA’ but the ‘artist’ property for id 5439 does not exist
how to add/delete or update properties of a JavaScript object?
Just example:
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'
}
};
recordCollection[9999] = {'whatever' : 'random stuff'}
console.log(recordCollection)
/* Output:
{
'1245': { artist: 'Robert Palmer', tracks: [] },
'2468': {
albumTitle: '1999',
artist: 'Prince',
tracks: [ '1999', 'Little Red Corvette' ]
},
'2548': {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: [ 'Let It Rock', 'You Give Love a Bad Name' ]
},
'5439': { albumTitle: 'ABBA Gold' },
'9999': { whatever: 'random stuff' }
}
*/
system
Closed
3
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.