TypeScript is implementing ES6 and ES7 features more and more with every new release. Now we have the awesome For-of loop in TypeScript 1.5.
I think you would agree that this code is not very readable.
Instead of printing out the items in the array to the console, the above code prints out the index of the array as follows.
Well that sucks.
TypeScript / ES6 Is To Rescue
We can use the For-of loop of ES6 in TypeScript today if you are using the very latest version of TypeScript.
The For-of Loop Of TypeScript
Due to this limitation of the For-in loop, ECMASCRIPT 6 introduces For-of loop.
For-of loop looks like this.
This code prints out the elements in the array as we would expect.
For-of loop is available in TypeScript 1.5. If you are compiling to ECMASCRIPT 5 in TypeScript, under the hood TypeScript is translating this into good old for loop as below.
Take a look at the live demo here.
The advantage of this is, our code looks sexy and readable and I personally think that is awesome.