I am still learning TypeScript and trying to accomplish a rather simple task, however the documentation does not provide guidance on how to iterate over JSON data. My goal is to loop through a JSON response array and insert a JSON object into each element. Here is the code I have been working on, but the TypeScript evaluator in WebStorm is flagging an error stating that speakerElement
is a string and not a JSON object, making it impossible to use the put
function.
return new Promise(resolve => {
this.http.get('http://.staging.wpengine.com/wp-json/wp/v2/cr3ativspeaker')
.map(res => res.json())
.subscribe(data => {
console.log("the speaker data is : ", data);
console.log("the speaker data is : ", JSON.stringify(data));
//get each speakers image and append it to their data
for(let speakerElement in <JSON>data) {
this.http.get('http://.staging.wpengine.com/wp-json/wp/v2/cr3ativspeaker')
.map(res => res.json())
.subscribe(response => {
speakerElement.put("media_details", response.media_details);
});
}
this.data = data;
resolve(this.data);
});
});