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) => {
...
});
I already checked the mongodb document, the nested array is indeed an array in the database.
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 :)