How can you use a for...in loop to access the properties of an object?

  • By using the index values.
  • By using the Object.keys() method.
  • By using the Object.entries() method.
  • By using the Object.getOwnPropertyNames() method.
A for...in loop is used to iterate over the enumerable properties of an object. To access the properties of an object, you can use the Object.keys() method, which returns an array of the object's own enumerable property names. This allows you to loop through the keys (property names) of the object and access their corresponding values. It's a safer and more controlled way to work with object properties than a simple for...in loop.
Add your answer
Loading...

Leave a comment

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