Skip to content

Latest commit

 

History

History
45 lines (25 loc) · 819 Bytes

Iterators.md

File metadata and controls

45 lines (25 loc) · 819 Bytes

Iterators

For of is used to iterate over the property values, instead of property names which is for in loop.

For in

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

For of loop prints property values.

Demo

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
}

⬆ back to top

Reference