I'm currently facing issues with filtering an array using an HTML
input
. Here is the code snippet in question:
ngOnInit() {
this.dtoService.setJsonResponse();
this.getPool();
}
getPool() {
this.json = this.dtoService.jsonResponse;
this.copyJson = Object.assign([], this.json);
}
filterArray(): void {
this.json = this.copyJson;
this.json.pools = this.json.pools.filter((e) =>
e.name.includes(this.filter));
console.log(this.copyJson);
}
Although the filtering function works as expected initially, I noticed that when a character is removed from the input field, the search results don't update accordingly. It appears that the copyJson
variable is also being modified, as when I print it out, it contains the same objects as the filtered json
. This seems to be related to references - any ideas on how to solve this issue?