What is the difference between for…in and for…of?

JavaScript Developer Medium

JavaScript Developer — Medium

What is the difference between for…in and for…of?

Key points

  • for...in: iterates over keys, including inherited ones
  • for...of: iterates over values of any iterable
  • for...in is used for objects, for...of is used for arrays
  • for...in can cause unexpected behavior with inherited properties

Ready to go further?

Related questions