How to get value in an object’s key using a variable referencing that key?

Use [] notation for string representations of properties:

console.log(obj[name]);

Otherwise it’s looking for the “name” property, rather than the “a” property.

Leave a Comment