I am working with an Array of Objects named comments, and my goal is to select only the ones that have a specific post id and copy them to another array of objects. The issue I am facing is finding a way to duplicate the object once it has been identified. Below is the function I have implemented:
comments = [];
commentspart = [];
private loadPartComments(id){
this.comments.forEach(element => {
if (element.postId == id) {
this.commentspart = ????;
}
});
return this.commentspart;
}
Any assistance would be greatly appreciated.