const persons = {
name: 'David',
age: 40
};
const myFunction = (x) => {
console.log(persons.x)
};
myFunction('name');
If I pass myFunction('name'), I expect it to print 'David'.
If I pass myFunction('age'), I expect it to print 40.
But now it prints undefined. Anyone has any solutions ?