Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
Nested Array forEach not working, is typeof object in console log

I'm using mongodb, nodejs and angular (v13.3.0) where i have a model with a nested array (array of arrays).

Data is fetched like this ...

export interface Post {
  _id: string;
  topicId: string;
  url: string;
  title: string;
  description: string;
  subject: string;
  type: PostType | string;
  lessonDate: string;
  lastUpdate: string;
  schoolWeek: number;
}

export interface PostMatching extends Post {
  elements: MatchingPair[][];
}

export type PostTypes = PostArticle | PostQuiz | PostMatching | PostIndexCards;

getPost(postUrl: string): Observable<PostTypes> {
    return this.httpClient.get<PostTypes>(`${this.POSTS_ENDPOINT}/url/${postUrl}`).pipe(
      map((response) => {
        // console.log('response GET post', response);
        return response;
      }),
    );
  }

on the nested array i need to do a for each loop but the reference is typeof object so i get the following error ...

const pairs = this.matching.elements[this.round];
pairs .forEach((pair) => {
  ...
});

enter image description here

I already checked the mongodb document, the nested array is indeed an array in the database.

enter image description here

My workaround looks like this ...

// TODO: check why array in array is typeof object
const pairs = Object.values(this.matching.elements[this.round]);

I wonder what is the problem here, i already checked the value with Array.isArray() which is false, also i logged the value in console and it seems the array is actually a object.

Anyone had this problem before? Thanks in advance :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!