Skip to content

Instantly share code, notes, and snippets.

@jasonmcleod
Created August 7, 2013 19:51
Show Gist options
  • Select an option

  • Save jasonmcleod/6177896 to your computer and use it in GitHub Desktop.

Select an option

Save jasonmcleod/6177896 to your computer and use it in GitHub Desktop.
array map
// 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