Currently, I am delving into the world of JavaScript and my instructor has assigned a task that involves utilizing information from a JSON file within our JavaScript code.
The issue I'm facing is deciphering how to effectively convert the JSON data into variables or arrays in JavaScript so that I can integrate it into my existing code seamlessly.
This is an example of how my JSON data is structured:
"id": 0,
"albumName":"Greatest hits",
"artistName":"ZZ-top",
"artistWebsite":"http://www.zztop.com/",
"productionYear": 1992,
"trackList":[
{
"trackNumber":1,
"trackTitle":"Gimme all your lovin'",
"trackTimeInSeconds":241
},
// Other tracks included in the JSON
]
},
My goal is to store this JSON data in the following variable structure:
artistName : "ArtistName",
albumName : "AlbumName",
noOfTracks : 0,
prodYear : 9999,
trackList : "",
init : function(artistName, albumName, noOfTracks, prodYear, trackList ){
this.artistName = artistName;
this.albumName = albumName;
this.noOfTracks = noOfTracks;
this.prodYear = prodYear;
this.trackList = trackList;
return this;
},