Skip to content

Instantly share code, notes, and snippets.

@duyenho
Created March 3, 2018 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save duyenho/5f984cdb8dae599aebd20f4be3870740 to your computer and use it in GitHub Desktop.
Save duyenho/5f984cdb8dae599aebd20f4be3870740 to your computer and use it in GitHub Desktop.
// For each image in the dataset, output this object:
// { src: "picture-3.jpg", caption: "Lorem Ipsum Dolor 2<br>Ut enim ad minim veniam, quis nostrud exercitation ullamco<br>2017" }
const data = [
{
"title": "Lorem Ipsum Dolor 1",
"description": "Ut enim ad minim veniam, quis nostrud exercitation ullamco.",
"year": "2018",
"images": [
"picture-1.jpg",
"picture-2.jpg"
]
},
{
"title": "Lorem Ipsum Dolor 2",
"description": "Ut enim ad minim veniam, quis nostrud exercitation ullamco",
"year": "2017",
"images": ["picture-3.jpg"]
},
]
const works = []
data.forEach(work => {
works.push(work.images.map(image => {
return {
"src": image,
"caption": `${work.title}<br>${work.description}<br>${work.year}`
}
}))
});
const flattenedWorks = [].concat.apply([], works);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment