So the problem I seem to be having is that when I populate my table the object discogsObjects.year populates my table consistently with "undefined" despite the fact that when I call it in devtools it returns values of years called from the API. My format is consistent with the code so I'm not sure what the problem could be...
Thank you!
var discogsObjects = {
title: [],
label: [],
year: [],
};
$(".artistform").submit(function(event){
event.preventDefault();
var band = ($("#userInput").val());
var url = "https://api.discogs.com/database/search?q=" + band + "&key=olnzRAzKsxiVlgocWNCH&secret=RPCwqvPXDmFkHHNzDePPKIcMsHRmNUIK"
$.ajax({
url: url,
type: "GET",
dataType: "json",
success: (data)=> {
console.log(data.results);
for (i = 0; i<21; i++) {
for(var key in data.results[i]){
//if (key === "id") idArr.push(data.results[i][key]);
if (key === "title") discogsObjects.title.push(data.results[i][key]);
if (key === "label") discogsObjects.label.push(data.results[i][key]);
if (key === "year") discogsObjects.year.push(data.results[i][key]);
}
//$thead(.hidden).show()
// $('#resultsHead').append('<tr><td>Year of Release</td><td>Artist Release</td><td>Record Label</td></tr>');
$('#resultsTable').append('<tr><td>'+discogsObjects.title[i]+'</td><td>'+discogsObjects.year[i]+'</td><td>'+discogsObjects.label[0]+'</td></tr>');
}
}
});
});