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.
Loading...
Related Quiz
- The ________ initiative aimed to standardize the core features of JavaScript.
- In the method myArray.map(callback), what is the second argument passed to the callback?
- You need to filter out the prototype properties while using a loop to iterate over object properties. Which loop would you use, and what additional method would be needed to avoid iterating over prototype properties?
- Which of the following patterns is NOT facilitated by using closures in JavaScript?
- _________ allows a function to access all the variables, as well as other functions, that are in its scope.