DEV Community

Discussion on: Difference between for...of and for...in loop in JavaScript.

Collapse
 
bradtaniguchi profile image
Brad

I used to get these mixed up all the time. Then I came up with a funny/simple saying.

"Use for...in if you want to be in trouble"

The most common use-case is to iterate over an array of things within an Array, where you'd want for...of, so using for...in would give you the "keys", or numbers which can create confusion.

You don't want to be "in" trouble, so don't use for...in. Hope that helps with remembering :D