JS: Difference Between for-in loop vs for-of loop

By Xah Lee. Date: . Last updated: .

What is the difference between for-in loop and for-of loop?

for-in Loop can be used on any object, and iterates its Enumerable string property keys, and will go up to the Prototype Chain.

for-of Loop work with Iterable Object only. The value that is iterated may or may not be properties. For example, for array object, it goes thru the array values (which are property values), but for {Map, Set} objects, it iterates their special values, for string object, it iterates thru the characters. Does not go up to the Prototype Chain.

JavaScript, Loop, Iteration

BUY Ξ£JS JavaScript in Depth