Categories
TypeScript Answers

How to loop through an array in TypeScript?

Spread the love

To loop through an array 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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *