For of
is used to iterate over the property values, instead of property names which is for in
loop.
For in
loop prints property name. See below example
Written in venilla js
var arr = [1, 2, 3, 4, 5, 6];
arr.obj = 'I am a string';
for (var i in arr) {
console.log(i); //print 0 1 2 3 4 5 obj, property names
}
For of
loop prints property values.
var arr = [1, 2, 3, 4, 5, 6];
arr.obj = 'I am a string';
for (var i of arr) {
console.log(i); //print 1 2 3 4 5 6, values not property name
}