I have an array, like
Array[{id:0,name:"a"},{id:1,name:"b"}...]
I have an other array, let's call it Array2, in Array2 I want those items from Arraywhere the id = given number.
I'm trying this with a function like:
saveActualComment() {
var i = 0;
for (i = 0; i < this.postComments.length; i++) {
if (this.postComments[i].postid = this.post.id) {
this.actualComments.push(this.postComments[i]);
}
}
}
Where postCommets is the Array, and actualComments is the Array2.
Problem is, that this function always gives me back the whole array, not only those items where the Array.id is the given number (post.id)
this.postComments[i].postidinstead of comparing its value. Use a double or triple equals instead, eg:if (this.postComments[i].postid === this.post.id) { ... }==in the if clause.