How would I write a function that takes an object, and a string of the name of a key in that object and return the value of that key?
For example:
retrieveKey({name: 'Joel'}, 'name') // returns 'Joel'
retrieveKey({password: 'Fruit!'}, 'password') // returns 'Fruit!'
retrieveKey({name: 'Joel'}, 'age') // returns undefined
Is this what you want?
let person1 = {name: "Joe", age: 18}
function getval(obj, key) {console.log(obj[key])}
getval(person1, "age") //returns 18