When dealing with object properties in the code snippet below, an error is thrown when trying to access the object using the Member Access. Why does this happen?
var d = {a: 10, b: 20, c:30};
var keys = Object.getOwnPropertyNames(d);
for(let i = 0; i < keys.length; i++){
console.log(d[keys[i]]);
//console.log(d.keys[i]); //throws error
}
In the given example, one possible explanation behind this issue could be that if we attempt to access it with the member access operator, it would directly try to access d
without properly initializing keys[i]
. Is this hypothesis accurate?