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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 usingfor...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