I am using rxjs
for filter and find the include value. but getting an error as TypeError: value.includes is not a function
any one correct me please?
here is my function:
fetchPaginatedList(pageSize, searchTerm) {
return this.list$
.pipe(
map((list) =>
list.filter((item) =>
Object.values(item).some((value) =>
value.includes(searchTerm)
)
)
),
map((list) => ({
size: list.length.toString(),
list: list.splice(0, pageSize),
}))
)
.toPromise();
}
what is the correct way to integrate the include
with rxjs filter?
CodePudding user response:
it should work:
fetchPaginatedList(pageSize, searchTerm) {
return this.list$
.pipe(
map((list) =>
list.filter((item) =>
Object.values(item).some((value) =>
value?.includes(searchTerm)
)
)
),
map((list) => ({
size: list.length.toString(),
list: list.splice(0, pageSize),
}))
)
.toPromise();
}
CodePudding user response:
When you are iterating oveer an object it might be a number as well. Here is a small modification of your code to transform object value to string https://stackblitz.com/edit/rxjs-gvxvop?devtoolsheight=60&file=index.ts
But you should understand that any complex structure, eg object as a property value, will break the code too.