How to access an object properties by using the dot notation in JavaScript

2 Answers

0 votes
const worker = {};

worker['firstname'] = 'Albus';
worker['lastname'] = 'Dumbledore';

console.log(worker.firstname);
console.log(worker.lastname);




/*
run:
 
"Albus"
"Dumbledore"
 
*/
  

 



answered Nov 17, 2020 by avibootz
0 votes
const worker = {
  firstname: 'Albus',
  lastname: 'Dumbledore'
};


console.log(worker.firstname);
console.log(worker.lastname);




/*
run:
 
"Albus"
"Dumbledore"
 
*/
  

 



answered Nov 17, 2020 by avibootz
...