After setting up a variable containing music library data...
var library = {
tracks: { t01: { id: "t01",
name: "Code Monkey",
artist: "Jonathan Coulton",
album: "Thing a Week Three" },
t02: { id: "t02",
name: "Model View Controller",
artist: "James Dempsey",
album: "WWDC 2003"},
t03: { id: "t03",
name: "Four Thirty-Three",
artist: "John Cage",
album: "Woodstock 1952"}
},
playlists: { p01: { id: "p01",
name: "Coding Music",
tracks: ["t01", "t02"]
},
p02: { id: "p02",
name: "Other Playlist",
tracks: ["t03"]
}
}
}
... I am seeking to display all playlists within the library with specific information:
p01: Coding Music - 2 tracks
p02: Other Playlist - 1 tracks
Currently, the output of my code is:
{ id: 'p01', name: 'Coding Music', tracks: [ 't01', 't02' ] }
{ id: 'p02', name: 'Other Playlist', tracks: [ 't03' ] }
This is the current code snippet being used:
var keys = Object.keys(library.playlists);
for(var i = 0; i < keys.length; i++) {
var key = keys[i];
console.log(library.playlists[key]);
}
If you have suggestions on how to adjust this code for the desired output, please share. Thank you!