Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,943 questions

51,883 answers

573 users

How to use for loop to print object values in JavaScript

1 Answer

0 votes
const workers = [
  {
    name: 'Albus Dumbledore',
    job: {
      language: 'javascript',
      years: 15
    },
    age: 54
  },
  {
    name: 'Rubeus Hagrid',
    job: {
      language: 'c++',
      years: 20,
    },
    age: 47
  }
];

for (const {name: n, job: {language: f, years: y}, age: a} of workers) {
  console.log('Name: ' + n + ', Language: ' + f + ', Years: ' + y + ', Age: ' + a);
}



/*
run:

"Name: Albus Dumbledore, Language: javascript, Years: 15, Age: 54"
"Name: Rubeus Hagrid, Language: c++, Years: 20, Age: 47"

*/

 



answered Nov 14, 2020 by avibootz
...