What is the primary use of the for...in loop in JavaScript?

  • Iterating over the values of an array
  • Iterating over the properties of an object
  • Executing a block of code repeatedly
  • Iterating over elements of an array in order
The for...in loop is primarily used for iterating over the properties of an object, not for arrays. It helps access each property name (key) of an object. Attempting to use it with arrays can lead to unexpected results, as it may also iterate over non-index properties added to the array.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *