'Queen' : {
'Album' : 'A night the Opera',
'Songs' : ['Bohemian Rhapsody','We are the Champions','Dont Stop Me Now']
},
'The Weeknd' : {
'Album' : 'After Hours',
'Songs' : ['Blinding Lights','After Hours','Heartless']
}
Im sorry but I still dont understand.
I’ll reframe the question for you.
How do I add an object to an object to an object?
var data = {
'Queen' : {
'Album' : 'A night the Opera',
'Songs' : ['Bohemian Rhapsody','We are the Champions','Dont Stop Me Now']
},
'The Weeknd' : {
'Album' : 'After Hours',
'Songs' : ['Blinding Lights','After Hours','Heartless']
}
As you can see ‘data’ is an object. Lets call that main object
‘Queen’ and ‘The Weeknd’ objects inside ‘data’. Lets call these sub objects.
‘Songs’ ,and ‘Album’ are mini objects.
My question is:
How do I add a new sub object with a mini object with a value in ‘data’
function updateData(name,prop,value) {
if(Object.keys(data).includes(name)){
return “Artist already exist”
}
/// do this
data[name] = { [prop] : value };
Can you please explain to me why should a bracket be used when its clearly a variable?
Then shoudnt ‘value’ also have brackets around it?
Thanks for the help though!!