December 2017
Beginner
372 pages
10h 32m
English
We used for...of loop earlier to loop through all the elements of a string, because the string implemented the Iterator interface. We have another function available for us by TypeScript, that is, for...in.
The major difference between both these functions is what they return as the value. The for...of will return the value of each element and the for...in will return the index of each element. The following is the example of both these functions.
let sampleArry = ["TypeScript","Angular","Node"];for(let val of sampleArry){ console.log(val);}for(let val in sampleArry){ console.log(val);}
The output of the for...of a loop will be TypeScript, Angular, and Node. The output for the for...in a loop will ...
Read now
Unlock full access