Below is the code to get the json data
export class AppComponent implements OnInit {
observableBooks: Observable<Book[]>
books: Book[];
errorMessage: String;
constructor(private bookService: BookService,private loki: LokiService) { }
ngOnInit(): void {
this.observableBooks = this.bookService.getBooksWithObservable();
this.observableBooks.subscribe(
books => this.books = books,
error => this.errorMessage = <any>error);
this.observableBooks.forEach(element => {
console.log(element);/// here I can get the json format as expected
// console.log(element.fname); //this is not working
// console.log(element.lname);// this is not working
});
}
}
Consider the json as like below
[{fname: "name1",lname: "name2"},{fname: "name3",lname: "name4"}]
I want to get the values of fname and lname.
Can anyone help me?
[].console.log(element[0].fname)?