Javascript: access object property

const obj = { name: 'John Foo', email: 'john.foo@aaa.com' };

let prop = 'name';
console.log(obj[prop]); // 'John Foo'

prop = 'email';
console.log(obj[prop]); // 'john.foo@aaa.com'



See also

No comments:

Post a Comment