Skip to content

Instantly share code, notes, and snippets.

@matthewsimo
Created July 22, 2019 23:42
Show Gist options
  • Save matthewsimo/a53c769fdc6dccfac3daaba980817a91 to your computer and use it in GitHub Desktop.
Save matthewsimo/a53c769fdc6dccfac3daaba980817a91 to your computer and use it in GitHub Desktop.
Help for Jed
// Fetch the book data
var books = fetch('http://someaweomseapi.com/api')
.then(function(response){
return response.json();
})
.then(function(json){
console.log('fetch result:', json)
return json
})
// Assuming json is an array here but something like this..
// Loop through each book and build the mark up for each, then join them without any separator
var booksHtml = books.map(function(book, index){
return '<li>' + index + ' - ' + book.title + '</li>';
}).join('');
// Inject the markup into some place in the DOM
var wrapper = document.querySelector('.some-unique-selector').html(booksHtml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment