Skip to content

Instantly share code, notes, and snippets.

Last active Jun 15, 2021
What would you like to do?
JavaScript Fetch api results on page
/* This is under Unlicense( and/or CC0( */
<!doctype html>
<html class="no-js" lang="">
<meta charset="utf-8">
<title>Fetch API Local</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<div id="nameHere"></div>
// Thanks to for the guidance
// thanks for explaining why it should be response here
.then(response => response.json())
.then(function (dataIn)
// to run the appendData function (bring in dataIn which has the object with all the data as an object)
.catch (function (err)
console.log('Error: ' + err);
function appendData(dataIn)
/* For loop, which loops through each item and gets the firstname and last name and puts in on a new line.
Guidance from:,
for (var i = 0; i !=; i++)
document.getElementById("nameHere").innerHTML += 'Name is: ' +[i].firstname + ' ' +[i].lastname + '<br>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment