Categories
TypeScript Answers

How to iterate over array of objects in TypeScript?

Spread the love

Sometimes, we want to iterate over array of objects in TypeScript.

In this article, we’ll look at how to iterate over array of objects in TypeScript.

How to iterate over array of objects in TypeScript?

To iterate over array of objects in TypeScript, we can use a for-of loop.

For instance, we write

for (const product of products) {
  console.log(product.productDesc);
}

to loop through the products array with a for-of loop.

In it, we log the productDesc property of the products object entry being looped through, which is stored in product.

Conclusion

To iterate over array of objects in TypeScript, we can use a for-of loop.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.