In the following example we are accessing properties of an object but why does accessing the object with the Member Access throw an error:
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
}
For example shown above, I would assume this would be because if we accessed it with the member access operator it would try to access d
immediately without initializing keys[i]
. Would this be correct?