I'm using Angular 6
.
In my component I have two array variables like
processedItems: Array<any> = [];
totalProductItems: Array<any> = [];
and processing functions like
ngOnInit() {
$products.forEach(async (e) => {
const res = await this.scraperService.scrapSingle(e.url).toPromise();
if (res.status.http_code === 200) {
const properties = this.scraperService.processSingleProduct(res.contents);
const p_item = {};
p_item['properties'] = properties;
this.totalProductItems.push(p_item);
this._applyFilter();
}
}
private _applyFilter() {
if (!this.filterData) {
// if nothing to filter, set totalProductItems;
this.processedItems = this.totalProductItems;
} else {
console.log('applying filter');
// reset processedItems
this.processedItems.length = 0;
// this now prints blank array
console.log(this.totalProductItems);
}
}
Setting length property of this.processedItems
to 0 is also emptying the this.totalProductItems
.
Why so? How can I keep these variables separate and independent?