Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Easy:
- the "i" in "in" stands for "index"
- the "o" in "of" stands for "object" (may be sth else, but you get the point) -
@k0pernikus obviously. Read the comment in brackets. 😉
edit:
Sry I was not clear enough. I was refering to what the loop variable will contain depending on "in" or "of". -
thealex11175y@PonySlaystation my way to remember it is similar:
- of: for every element "of" the array
- in: for every number "in" the "in"dices
Edit: though I think of it as an array the mnemonic usually works for everything. -
I got so used to for..of that I know it's the regular for each. So for..in is the other one lol
-
jdebs3385yYeah I always mix these up too. Sometimes I remember by thinking "in" sounds like that start of "enumerable properties", or you look "in an object".
But I still have to look them up, because I almost never use them. I prefer to just use Object.keys and then map or whatever.
I always confuse `for..in` with `for..of` and have to look up their respective meaning. Again.
It drives me crazy.
Do you have any mnemonic on this? How do you remember the difference?
(Now, as in this very moment, I know that for..in is for looping over keys of an object and for..of for looping over iterators. But tomorrow I will have forgotten it again.)
rant
dx
loop
forgetful
for..of
for..in
javascript