Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

80
Views
Javascript class with arrays retrieving data

I have a javascript class like this:

class transportDetails{
    constructor(){
        this.car_data     = [[3,0]];  
        this.bike_data    = [[7,2]];
        this.van_data     = [[1,0]];
        this.train_data   = [[9,3]];
    }
 }

 transport = new transportDetails();

This is fine and works ok. But how can I perform a loop through the property names and obtain their individual values?

 for(n=0; n<=3; n++){
    a2 = transport.transportDetails(Object.getOwnPropertyNames(race));
 }

But instead of just getting the property names, i.e, car_data, bike_data etc. I would also get the value of the two dimensional array?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Do this way :

class transportDetails{
    constructor(){
        this.car_data     = [[3,0]];  
        this.bike_data    = [[7,2]];
        this.van_data     = [[1,0]];
        this.train_data   = [[9,3]];
    }
 }
 transport = new transportDetails();

 Object.keys(transport).forEach(key=>{
 console.log("key is. : ",key);
 console.log("value is. : ",transport[key]);
})

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!