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,851 questions

51,772 answers

573 users

How to create and use an array of objects in JavaScript

3 Answers

0 votes
const workers = [
    { id: 13451, name: 'Axel'},
    { id: 87134, name: 'Blaze'},
    { id: 79372, name: 'Arti'},
    { id: 39810, name: 'Isla'}
];
  
for (let i = 0; i < workers.length; i++) {
    console.log(workers[i].id + " " + workers[i].name);
}
  
  
  
/*
run:
      
13451 Axel
87134 Blaze
79372 Arti
39810 Isla

*/
 

 
 

 



answered Nov 1, 2019 by avibootz
edited May 28, 2025 by avibootz
0 votes
const workers = [
    {
        id: 82927,
        name: "Axel",
        age: 37
    },
    {
        id: 98272,
        name: "Blaze",
        age: 41
    },
    {
        id: 76362,
        name: "Isla",
        age: 31
    }
];
  
  
console.log(workers[0].id + " " + workers[0].name + " " + workers[0].age);
console.log(workers[2].id + " " + workers[2].name + " " + workers[2].age);


  
/*
run:
      
82927 Axel 37
76362 Isla 31
   
*/

 



answered Nov 1, 2019 by avibootz
edited May 28, 2025 by avibootz
0 votes
const workers = [
    {
        id: 82927,
        name: "Axel",
        age: 37,
        show_details() {
            return(this.id + " " + this.name + " " + this.age);
        }
    },
    {
        id: 98272,
        name: "Blaze",
        age: 41
    },
    {
        id: 76362,
        name: "Isla",
        age: 31
    }
            
];
  
console.log(workers[0].show_details());
 
  
/*
run:
      
82927 Axel 37
   
*/

 



answered Nov 2, 2019 by avibootz
edited May 28, 2025 by avibootz
...