5
我有一個名爲comments的對象數組,我試圖只選擇一個具有我需要的郵件的ID給另一個對象數組。問題是我無法找到複製我找到的對象的方法。這是我的功能:Angular2 foreach對象?
comments = [];
commentspart = [];
private loadPartComments(id){
this.comments.forEach(element => {
if (element.postId == id) {
this.commentspart = ????;
}
});
return this.commentspart;
}
謝謝。
怎麼樣:'this.commentspart = element;'? –