My current challenge involves working with arrays. Here is an example of the array I am dealing with:
Array[{id:0,name:"a"},{id:1,name:"b"}...]
In addition to this array, I have another array called Array2
. My goal is to extract items from Array
where the id
matches a given number.
I am attempting to achieve this using the following function:
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]);
}
}
}
In this function, postCommets
represents the original Array
, while actualComments
stands for the extracted items in Array2
.
However, the issue I am facing is that this function returns the entire array instead of just the items where the Array.id
matches the given number (post.id
).