I’m using spread to “merge” the objects from my functions into a single object. I want to check if the values I’m sending at my “profiles” array of strings matches any of the values at the merged object and print them.
async getAll() {
try {
const triangles = await this.getAlltriangles(true);
const squares = await this.getAllsquares(true);
const circles = await this.getAllcircles(true);
const output = {
...triangles, ...squares, ...circles,
};
console.log('unified list:', output);
console.log(typeof (output)); // just double checking if the outcome is an array indeed
return output;
} catch (error) {
this.logger.error(error);
}
}
The next function will try doing the operation. I’m trying to work with filter
and includes
:
async findProfiles(profiles: string[], authorizedUser: string) {
if (!authorizedUser) return 'Invalid User';
if (!profiles || profiles.length === 0) {
return 'No profiles were informed';
}
try {
await this.getAll();
const getAllarray = await this.getAll();
const matches = getAllarray.filter((obj) => profiles.includes(obj.name));
console.log(matches);
return { matches };
} catch (error) {
console.log(error);
return error;
}
}
this line const matches = getAllarray.filter((obj) => profiles.includes(obj.name));
returns me an empty object instead ,along with a TypeError: getAllarray.filter is not a function