Is there any way, how to iterate over object which we got in controller by @Query()
anotations?
We have dynamic count and name of query parameters in GET, so we need to take whole @Query()
object and iterate over them to know what paramas we exactly have.
But if I want to iterate over that object I got error that object is not iterable.
Any idea how to do that?
You can use Object.keys()
to get an array of the keys of the query object. You can then iterate over this array of keys:
@Get()
getHello(@Query() query) {
for (const queryKey of Object.keys(query)) {
console.log(`${queryKey}: ${query[queryKey]}`);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With