-
-
Save jasonmcleod/6177896 to your computer and use it in GitHub Desktop.
array map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // create an empty array and hydrate it | |
| var items = []; | |
| data.map(function (item) { | |
| if (item.kind === 'track') { | |
| items.push({ | |
| id: item.id, | |
| title: item.title, | |
| provider: self.provider, | |
| artist: item.user.username, | |
| artwork: item.artwork_url, | |
| length: (item.duration/1000), | |
| // meta: item | |
| }); | |
| } | |
| }); | |
| // let map return the new array | |
| var items = data.map(function (item) { | |
| if (item.kind === 'track') { | |
| return{ | |
| id: item.id, | |
| title: item.title, | |
| provider: self.provider, | |
| artist: item.user.username, | |
| artwork: item.artwork_url, | |
| length: (item.duration/1000), | |
| // meta: item | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment