Reputation: 39364
I have the following object in typescript:
let parameters = { include: 'tags', limit: 20, published: true };
How can I loop through each parameter and get its key and value?
I need to do something with the key and value when value is not undefined.
Upvotes: 0
Views: 52
Reputation: 1074078
Use Object.entries
, perhaps with a for-of
loop and destructuring:
for (const [key, value] of Object.entries(parameters)) {
if (value !== undefined) {
// ...use `key` and `value` here
}
}
Upvotes: 4