I'm kinda new to JavaScript and jQuery, but I'm learning while I'm making things. Now I'm working with the last.fm api for JS (https://github.com/fxb/javascript-last.fm-api), and I'm trying to get the first album of my list.
I fetch the data with following code:
lastfm.track.getInfo({track: activeMedia.title, artist: activeMedia.author}, {success: function(trackInfoResult){
// doing things with trackInfoResult
}, error: function(code, message){
console.log("Error code: " + code);
}});
The output for this is in the following structure (found on http://www.last.fm/api/show/track.getInfo):
<track>
<id>1019817</id>
<name>Believe</name>
<mbid/>
<url>http://www.last.fm/music/Cher/_/Believe</url>
<duration>240000</duration>
<streamable fulltrack="1">1</streamable>
<listeners>69572</listeners>
<playcount>281445</playcount>
<artist>
<name>Cher</name>
<mbid>bfcc6d75-a6a5-4bc6-8282-47aec8531818</mbid>
<url>http://www.last.fm/music/Cher</url>
</artist>
<album position="1">
<artist>Cher</artist>
<title>Believe</title>
<mbid>61bf0388-b8a9-48f4-81d1-7eb02706dfb0</mbid>
<url>http://www.last.fm/music/Cher/Believe</url>
<image size="small">http://userserve-ak.last.fm/serve/34/8674593.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/8674593.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/8674593.jpg</image>
</album>
<toptags>
<tag>
<name>pop</name>
<url>http://www.last.fm/tag/pop</url>
</tag>
...
</toptags>
<wiki>
<published>Sun, 27 Jul 2008 15:44:58 +0000</published>
<summary>...</summary>
<content>...</content>
</wiki>
</track>
Getting my artist name, and id I can manage by the following code:
console.log(rackInfoResult.track.name);
But now I want to have the first album. How can I select the album with position="1"?