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 the for-of loop.
For instance, we write
for (const product of products) {
console.log(product.productDesc);
}
to loop through the products
array.
product
is the object being iterated through, so we can get the productDesc
property from the object.
Conclusion
To iterate over array of objects in TypeScript, we can use the for-of loop.