How can a "for" loop be used to iterate through the properties of an object?

  • By using for...of loop
  • By using for...in loop
  • By using forEach method
  • By using while loop
To iterate through the properties of an object, you should use a for...in loop. This loop iterates over the enumerable properties of an object and allows you to access each property name (key). The for...of loop is used for iterating over iterable objects like arrays. The forEach method is specifically used for arrays, and while loops are generally used for repetitive tasks with a condition.
Add your answer
Loading...

Leave a comment

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