Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda