I'm trying to return an album object given a specified track. Given this array:
const albumCollection = [
{
id: 2125,
title: 'Use Your Illusion',
artist: "Guns N' Roses",
tracks: ['November Rain', "Don't Cry"]
},
{
id: 2975,
title: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
{
id: 1257,
title: 'Transformer',
artist: 'Lou Reed',
tracks: ['Vicious', 'Perfect Day', 'Walking on the Wild Side']
},
And using the following function, both the commented and uncommented code returns undefined. I'm trying to understand why. What I'm trying to do is return the album as an object based on the track name.
function getAlbumWithTrack(track) {
/*
const result = albumCollection.find((item) => item.id === track);
console.log(result);
*/
return albumCollection.find(function (title) {
return title.track === track;
});
}
console.log(getAlbumWithTrack('Little Red Corvette'));
console.log(getAlbumWithTrack('November Rain'));
console.log(getAlbumWithTrack('perfect day'));