Estoy usando mongodb, nodejs y angular (v13.3.0) donde tengo un modelo con una matriz anidada (matriz de matrices).
Los datos se obtienen así...
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; }), ); }en la matriz anidada, necesito hacer un para cada bucle, pero la referencia es tipo de objeto, por lo que aparece el siguiente error ...
const pairs = this.matching.elements[this.round]; pairs .forEach((pair) => { ... });Ya revisé el documento mongodb, la matriz anidada es de hecho una matriz en la base de datos.
Mi solución se ve así...
// TODO: check why array in array is typeof object const pairs = Object.values(this.matching.elements[this.round]);Me pregunto cuál es el problema aquí, ya verifiqué el valor con Array.isArray() que es falso, también registré el valor en la consola y parece que la matriz es en realidad un objeto.
¿Alguien tuvo este problema antes? Gracias por adelantado :)