Just starting out in JS and I am attempting to use a for loop to combine all the 'text' from various JSON objects into one cohesive paragraph. For example, it should read like this: "Hello, and welcome to the Minute Physics tutorial on basic Rocket Science. Before we get started, I'd like to quickly announce that I'm now making these videos at the perimeter institute for theoretical physics"
function loadRequest() {
var data = null;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var obj = JSON.parse(this.responseText);
for(var i = 0; i < json.length; i++) {
var obj = json[i];
document.getElementById("text").innerHTML = obj.text;
}
}
}
xhttp.open("GET", "https://fakeapi.p.rapidapi.com/sample", true);
xhttp.setRequestHeader("x-rapidapi-host", "fakeapi.p.rapidapi.com");
xhttp.setRequestHeader("x-rapidapi-key", "APIKey");
xhttp.send();
}
JSON:
"[ { 'index': 0, 'start': 0.03, 'dur': 4.499, 'end': 4.529, 'text': 'Hello, and welcome to the Minute Physics tutorial on basic Rocket Science. Before we get started,' }, { 'index': 1, 'start': 4.529, 'dur': 4.17, 'end': 8.699, 'text': 'I'd like to quickly announce that I'm now making these videos at the perimeter institute for theoretical physics' },