Create a Multidimensional Array5:32 with Guil Hernandez
Create a program that uses a multidimensional array to hold songs and artists, and then displays a playlist of each song, with the artist who recorded it and the duration of the song.
Multidimensional array snippet
const playlist = [ ['So What', 'Miles Davis', '9:04'], ['Respect', 'Aretha Franklin', '2:45'], ['What a Wonderful World', 'Louis Armstrong', '2:21'], ['At Last', 'Ella Fitzgerald', '4:18'], ['Three Little Birds', 'Bob Marley and the Wailers', '3:01'], ['The Way You Look Tonight', 'Frank Sinatra', '3:21'] ];
- Creating a two-dimensional array - MDN
Spread syntax and multidimensional arrays
Note: Spread syntax effectively goes one level deep while copying an array. Therefore, it may be unsuitable for copying multidimensional arrays, as the following example shows.
const brass = [ ['trumpet'], ['tuba'], ['trombone'] ]; const instruments = [...brass]; instruments.shift().shift(); // "trumpet" // Notice how the brass array is also affected by this: brass // [ , ["tuba"], ["trombone"] ]
You need to sign up for Treehouse in order to download course files.Sign up