I am quiet new in TypeScript and JavaScript and I have a problem. I have function that I copy-pasted from another app, but I slightly modified it:
myServer.prototype.filterList = function(_data, filterModel) {
const resultOfFilter = [];
function filterData(filtModel) {
let httpParams = new HttpParams();
for (const f in filtModel) {
// some code
}
const httpOptions = {
params: httpParams,
};
return that.httpClient.get(`${baseUrl}${tableName}`, httpOptions);
}
filterData(filterModel).subscribe((filteredData: any[] ) => {
filteredData.forEach((item) => {
resultOfFilter.push(item);
});
});
return resultOfFilter;
};
This function returns an array like that:
I pass this array to another function where I want to iterate over its items. I tried following approaches:
a)
resultOfFilter.forEach(i => {
console.log('I:', i);
});
b)
for (let i; i <= resultOfFilter.length; i++){console.log('I:', resultOfFilter[i]);}
c)
Object.keys(resultOfFilter).forEach(i => {
console.log('I:', i);
});
But all these functions did not work for me. And I can't understand why. I can display the whole array, but I can't get its items for some reason.
Please advise how can I get each item of that array.
P.S.: When I use typeof resultOfFilter
I get object
.