I created an xhr request which gives back an object with an array of names which I want to write to the document. here is the object I receive from the request:
{description: "Names for employee feed", employees: Array(8)}
description: "Names for employee feed"
employees: Array(8)
0: {id: 1, first_name: "Allef", last_name: "Vinicius"}
1: {id: 2, first_name: "Brook", last_name: "Cagle"}
2: {id: 3, first_name: "Fayard", last_name: "Nicolas"}
3: {id: 4, first_name: "Hasana", last_name: "Ayubu"}
4: {id: 5, first_name: "Jake", last_name: "Young"}
5: {id: 6, first_name: "Michelangelo", last_name: "Buonarroti"}
6:
id: 7
first_name: "Moiraine"
last_name: "Damodred"
__proto__: Object
7: {id: 8, first_name: "Rand", last_name: "Al'Thor"}
length: 8
I'm can write the "description" to the document but I am having trouble accessing the names in the array.
const output = document.querySelector('.output');
let xhr = new XMLHttpRequest();
xhr.open('GET', 'https://techi.envivent.com/names.json', true);
xhr.onload = function(){
if (this.status === 200) {
let response = JSON.parse(this.responseText);
console.log(response);
output.innerHTML = `<h3>${response.description}<h3>
<p>${response.employee[0][1]}</p>
`;
}
}
xhr.send();