How can I extract object array values from a data array? Here is the code I am using:
Component
FmtNews(mediasource) {
let body = mediasource;
console.log("Testing body:" +body)
this.commonService.getTopNews(body)
.subscribe((res) => {
if (res['status'].code === 102) {
// this.headerService.isLoading = false;
console.log(res['data'])
}
});
}
When I run console.log(res['data'])
, I receive output like this:
(4)[..]
0: Object (mediaSource: "News Today", pageUrl: "https://www.newstoday.com", contents:)
1:Object (mediaSource: "News Today", pageUrl: "https://www.newstoday.com", contents:)
2:Object (mediaSource: "News Today", pageUrl: "https://www.newstoday.com", contents:)
3:Object (mediaSource: "News Today", pageUrl: "https://www.newstoday.com", contents:)
My issue is... How do I access the data within these objects to display on an HTML page?
HTML
<div class="media">
<img class="mr-3" src="..." alt="Generic placeholder image">
<div class="media-body">
<h5 class="mt-0">title here</h5>
<span>url here</span>
<div>
contents here
</div>
</div>
</div>