简体   繁体   中英

How to access nested arrays of objects

I am subscribing to my data from an http get method:

  getEds(): void {
    this.edService.getEds()
      .subscribe((eds: Education) => {
        this.eds = eds.educationData;
        console.log(this.eds:codeschool);
      });
  }

I am trying to display my courses for codeschool in an *ngFor loop but do not know how to access the data. My console log will show the entire array of objects so I know I am receiving the correct info. I've tried various syntax:

.subscribe((eds: any) => {
            this.eds = eds.educationData.course;

.subscribe((eds: any) => {
            this.eds = eds.educationData['codeschool'];

.subscribe((eds: any) => {
            this.eds = eds.educationData.codeschool;

None of these syntax work and the log shows undefined. I found this page which has great info and what I tried to use as a baseline.

Access / process (nested) objects, arrays or JSON

However, I do not know what is wrong or why I cannot get the data I need. When I use

  .subscribe((eds: any) => {
    this.eds = eds.educationData;

and I log out (this.eds), my log shows:

[{…}] 
0:{codeschool: Array(14), egghead: Array(6)}
 length:1
 __proto__:Array(0)

Beyond this I haven't been able to get the data I want...... :(

用这个 :

eds.educationData[0].codeschool

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM