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

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,703 questions

55,462 answers

573 users

How to create and use an array of objects in Node.js

3 Answers

0 votes
const workers = [
    { id: 123451, name: 'Suki'},
    { id: 875134, name: 'Clarke'},
    { id: 793772, name: 'Teo'},
    { id: 369810, name: 'Isla'}
];
   
for (let i = 0; i < workers.length; i++) {
    console.log(workers[i].id + " " + workers[i].name);
}
   
   
   
/*
run:
       
123451 Suki
875134 Clarke
793772 Teo
369810 Isla
 
*/
 

 



answered May 28, 2025 by avibootz
0 votes
const workers = [
    {
        id: 825927,
        name: "Isla",
        age: 37
    },
    {
        id: 980272,
        name: "Clarke",
        age: 41
    },
    {
        id: 763162,
        name: "Teo",
        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:
       
825927 Isla 37
763162 Teo 31
 
*/
 

 



answered May 28, 2025 by avibootz
0 votes
const workers = [
    {
        id: 825927,
        name: "Isla",
        age: 31,
        show_details() {
            return(this.id + " " + this.name + " " + this.age);
        }
    },
    {
        id: 980272,
        name: "Clarke",
        age: 46
    },
    {
        id: 763162,
        name: "Teo",
        age: 51
    }
];
   
   
console.log(workers[0].show_details());
   
   
/*
run:
       
825927 Isla 31
 
*/
 

 



answered May 28, 2025 by avibootz
...