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.
Loading...
Related Quiz
- Which of the following patterns is NOT facilitated by using closures in JavaScript?
- What is the primary difference between for...in and for...of loops?
- What is the purpose of the status property in an HTTP response?
- In a while loop, forgetting to update the condition can lead to a/an ________ loop.
- What is a potential downside of using async/await syntax?